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

Rust | if let statement example: Write an example to check whether the given number is Even or Odd.
Submitted by Nidhi, on October 07, 2021

Problem Solution:

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

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.

Rust if/else Programs »






Comments and Discussions!

Load comments ↻






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