ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the if statement

Rust | if statement example: Given a number, we have to check whether it is even or not.
Submitted by Nidhi, on October 03, 2021

Problem Solution:

Here, we will create an integer variable and then check whether the variable contains an ODD or EVEN number using the if statement.

Program/Source Code:

The source code to demonstrate the if statement is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate 
// the if statement

fn main() {
    let mut num:i32 = 22;

    if(num%2 == 0)
    {
        println!("Number is EVEN");
    }
    if(num%2 != 0)
    {
        println!("Number is ODD");
    }
}

Output:

Number is EVEN

Explanation:

Here, we created a 32-bit integer variable num with the initial value of 22. Then we checked the num variable contains an ODD or EVEN number using the if statement.

Rust if/else Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.