Arithmetic/Integer: Difference between revisions

Line 2,715:
 
Note that this code cannot be run within the [http://play.rust-lang.org Rust playpen] as it does not support console input.
<lang rust>use std::ioenv;
 
fn main() {
let args: Vec<_> = env::args().collect();
#![allow(unstable)] // Currently required whilst Rust 1.0 is finalised
let a: i32 = from_str(ioargs[1].parse::stdin().read_line().unwrap().trim().as_slice<i32>()).unwrap();
let b: i32 = from_str(ioargs[2].parse::stdin().read_line().unwrap().trim().as_slice<i32>()).unwrap();
 
let println!("sum: ={}", a + b);
println!("adifference: + b = {0}" , suma - b);
println!("aproduct: - b = {0}" , a -* b);
println!("a * binteger =quotient: {0}" , a */ b); // truncates towards zero
println!("quotientremainder: of a / b = {0}" , a /% b); // truncatessame sign as towardsfirst 0operand
println!("remainder of a / b = {0}" , a % b); // same sign as first operand
}</lang>
 
Anonymous user