Q:

Rust program to demonstrate the conditional operator

belongs to collection: Rust Basic Programs

0

Here, we will demonstrate the conditional/ternary operator to find out the 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 demonstrate the conditional operator is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate 
// the conditional operator

fn main() {
    let mut num:i32=22;  
    if (num%2==0) { println!("EVEN") } else { println!("EVEN") }
}

Output:

EVEN

Explanation:

Here, we created an integer variable num initialized with 22. Then we used the ternary operator to find out the number is EVEN or ODD and printed the appropriate message.

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

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to demonstrate the bitwise left-shift... >>
<< Rust program to demonstrate the logical NOT (!) op...