Q:

Rust program to check a given number EVEN or ODD using bitwise operator

belongs to collection: Rust Basic Programs

0

Here, we will create a 16-bit integer number and then we will check the given number is EVEN or ODD using a bitwise operator and print an appropriate message.

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 check a given number EVEN or ODD using a bitwise operator is given below. The given program is compiled and executed successfully.

// Rust program to check a given number 
// EVEN or ODD using bitwise operator

fn main() 
{
    let mut num:i16 = 5;
    
    if(num & 1 == 1)
    {
		println!("ODD number");
	}
	else
	{
		println!("EVEN number");
	}
}

Output:

ODD number

Explanation:

Here, we created a 16-bit integer variable num with an initial value of 5. Then we found the given 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 check a number contain the alterna... >>
<< Rust program to count the total number of trailing...