ADVERTISEMENT
ADVERTISEMENT

Rust program to print the EVEN numbers using Command Line Arguments

Rust Example: Write a program to print the EVEN number using Command Line Arguments.
Submitted by Nidhi, on November 26, 2021

Problem Solution:

In this program, we will find the EVEN numbers in Command Line Arguments and printed them.

Program/Source Code:

The source code to print the EVEN number using Command Line Arguments is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.

// Rust program to print the EVEN numbers 
// using Command Line Arguments

fn main(){
   	let args = std::env::args(); 
   	let mut num=0;
   	let mut cnt=0;

   	for arg in args {
   		if cnt>0{
			num = arg.parse::<i32>().unwrap();
			
			if num%2==0{
				print!("{} ",num);
			}
		}
		cnt=1;
   	}
   	
   	println!();
}

Output:

$ rustc CheckEven.rs

Execute:
$ ./CheckEven 10 15 20
10 20

Explanation:

In the main() function, we found the even numbers in Command Line Arguments and printed them.

Rust Miscellaneous Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
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.