ADVERTISEMENT
ADVERTISEMENT

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 »



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.