Arithmetic/Integer: Difference between revisions
Content added Content deleted
Line 2,715: | 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. |
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:: |
<lang rust>use std::env; |
||
fn main() { |
fn main() { |
||
let args: Vec<_> = env::args().collect(); |
|||
#![allow(unstable)] // Currently required whilst Rust 1.0 is finalised |
|||
let a |
let a = args[1].parse::<i32>().unwrap(); |
||
let b |
let b = args[2].parse::<i32>().unwrap(); |
||
println!("sum: {}", a + b); |
|||
println!(" |
println!("difference: {}", a - b); |
||
println!(" |
println!("product: {}", a * b); |
||
println!(" |
println!("integer quotient: {}", a / b); // truncates towards zero |
||
println!(" |
println!("remainder: {}", a % b); // same sign as first operand |
||
println!("remainder of a / b = {0}" , a % b); // same sign as first operand |
|||
}</lang> |
}</lang> |
||