rust 整数加减乘除


use std::io;
fn main() {
        let mut first = String::new();

        io::stdin().read_line(&mut first)
            .ok()
            .expect("failed to read line");

        let first: u32 = first.trim().parse()
            .ok()
            .expect("Please type a number!");

        let mut second = String::new();

        io::stdin().read_line(&mut second)
            .ok()
            .expect("failed to read line");

        let second: u32 = second.trim().parse()
            .ok()
            .expect("Please type a number!");


 let c=first+second;
 let d=first-second;
 let e=first*second;
 let f=first/second;
 let md=first%second;

println!("add is: {}\nsub is: {}\nplus is: {}\ndiv is: {}", c,d,e,f);
println!("和是: {}\n差是: {}\n积是: {}\n商是: {}", c,d,e,f);
println!(" {}", md);}

运行结果


promote:all $ cargo build
   Compiling all v0.1.0 (file:///Users/yangfeng/rustprj/all)
promote:all $ cargo run
     Running `target/debug/all`
32
4
add is: 36
sub is: 28
plus is: 128
div is: 8
和是: 36
差是: 28
积是: 128
商是: 8
 0


你可能感兴趣的:(高级计算与工程)