Rust program to perform the arithmetic operations
kw.rs
fn main()
{
    println!("Addition {}",10+10);
    println!("Subtraction {}",10-20);
    println!("Multiplication {}",-10*20);
    println!("Division {}",-200/20);
    println!("Modulus {}",-10%3);
}
Output
kodingwindow@kw:~$ rustc kw.rs
kodingwindow@kw:~$ ./kw Addition 20 Subtraction -10 Multiplication -200 Division -10 Modulus -1 kodingwindow@kw:~$
Example 2: Rust program to perform the arithmetic operations
kw.rs
fn main()
{
    let a=10;
    let b=20;
    println!("Addition {c}",c=a+b);
    println!("Subtraction {c}",c=a-b);
    println!("Multiplication {c}",c=a*b);
    println!("Division {c}",c=b/a);
    println!("Modulus {c}",c=b%a);
}
Output
kodingwindow@kw:~$ rustc kw.rs
kodingwindow@kw:~$ ./kw Addition 30 Subtraction -10 Multiplication 200 Division 2 Modulus 0 kodingwindow@kw:~$
Example 3: Rust program to perform the arithmetic operations
kw.rs
fn main()
{
    let a:f32=3.14;
    let b:f32=3.14;
    println!("Addition {c}",c=a+b);
    println!("Subtraction {c}",c=a-b);
    println!("Multiplication {c}",c=a*b);
    println!("Division {c}",c=b/a);
    println!("Modulus {c}",c=b%a);
}
Output
kodingwindow@kw:~$ rustc kw.rs
kodingwindow@kw:~$ ./kw Addition 6.28 Subtraction 0 Multiplication 9.859601 Division 1 Modulus 0 kodingwindow@kw:~$
Advertisement