Rust program to demonstrate the if-else statement

Rust | if-else statement example: Given a number, we have to check whether the variable contains an ODD or EVEN number using the if-else statement.
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-else statement.

Program/Source Code:

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

// Rust program to demonstrate 
// the if-else statement

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

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

Output:

Number is ODD

Explanation:

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

Rust if/else Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.