Q:

Rust program to demonstrate the if statement

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now