Rust Program to Create a Closure Function to Check Given Number Is EVEN or ODD

You are currently viewing Rust Program to Create a Closure Function to Check Given Number Is EVEN or ODD

Rust program to create a closure function to check given number is EVEN or ODD

// Rust program to create a closure function 
// to check given number is EVEN or ODD

fn main() 
{
	let num1 = 10;
	let num2 = 21;

	let check_even = |n|
	{
		if n%2==0
		{
			println!("EVEN");
		}
		else
		{
			println!("ODD");
		}
	};

	check_even(num1);
	check_even(num2);
}

Output

EVEN
ODD

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply