Skip to content

Instantly share code, notes, and snippets.

@greyblake
Created August 27, 2016 14:55
Show Gist options
  • Save greyblake/a5caf7dfb649e78baaefcff16a8f5283 to your computer and use it in GitHub Desktop.
Save greyblake/a5caf7dfb649e78baaefcff16a8f5283 to your computer and use it in GitHub Desktop.
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