ADVERTISEMENT
ADVERTISEMENT

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

Here, we are going to learn how to check whether a given number EVEN or ODD using bitwise operator in Rust programming language?
Submitted by Nidhi, on September 24, 2021

Problem Solution:

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.

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.

Rust Basic 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.