Created
August 27, 2016 14:55
-
-
Save greyblake/a5caf7dfb649e78baaefcff16a8f5283 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let funcs = [ | |
("+", sum as fn(f64, f64) -> f64), | |
("-", sub), | |
("*", mult), | |
("/", div), | |
("^", pow) | |
]; | |
for &(name, func) in funcs.iter() { | |
for a in 1..4 { | |
for b in 1..4 { | |
println!("{} {} {} = {}", a, name, b, func(a as f64, b as f64)); | |
} | |
} | |
println!(""); | |
} | |
} | |
fn sum(a : f64, b : f64) -> f64 { | |
a + b | |
} | |
fn sub(a : f64, b : f64) -> f64 { | |
a - b | |
} | |
fn pow(a : f64, b : f64) -> f64 { | |
a.powf(b) | |
} | |
fn mult(a : f64, b : f64) -> f64 { | |
a * b | |
} | |
fn div(a : f64, b : f64) -> f64 { | |
a / b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment