Q:

Rust program to check the Even or Odd number using the if let statement

belongs to collection: Rust if/else Programs

0

In this program, we will use the if let statement to find out the given number is EVEN or ODD.

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 find the Even/Odd using the if let statement is given below. The given program is compiled and executed successfully.

// Rust program to find the Even/Odd 
// using the if let statement

fn main() 
{
    let num: i32 = 23;
    
    let result = if let 0=num%2{
        "Even"
    }
    else{
        "Odd"
    };
    
    println!("Number is: {}",result);
}

Output:

Number is: Odd

Explanation:

Here, we created a variable num  of i32 type with the initial value of 23. Then we checked variable num contains an EVEN or ODD number using the if let statement. After that, we printed the result.

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

total answers (1)

<< Rust program to demonstrate the if let with else i...