Home »
Rust »
Rust Programs
Rust program to demonstrate the conditional operator
Here, we are going to demonstrate the conditional operator in Rust programming language.
Last Updated : September 22, 2021
Problem Statement
Here, we will demonstrate the conditional/ternary operator to find out the number is EVEN or ODD.
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.
Rust Basic Programs »
Advertisement
Advertisement