Rust program to print the EVEN numbers using Command Line Arguments


Print the EVEN numbers using Command Line Arguments

Rust Programming Language


Print the EVEN numbers using Command Line Arguments


Problem


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


Input


// 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!();
}{codeBox}


Output


$ rustc CheckEven.rs

Execute:
$ ./CheckEven 10 15 20
10 20{codeBox}


Explanation


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



Post a Comment