Skip to content

Commit

Permalink
Factorial in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay9596 committed Oct 11, 2017
1 parent 490a06a commit bd1a465
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions math/factorial/Rust/factorial.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::io;

fn fact(n:i32) -> f64 {
match n {
0 => 1.0,
_ => n as f64 * fact(n-1)
}
}

fn main() {
println!("Enter a number");
let mut num = String::new();
io::stdin().read_line(&mut num);
let num : i32 = num.trim().parse().unwrap();
println!("factorial of {} = {}",num,fact(num));
}

0 comments on commit bd1a465

Please sign in to comment.