From a80785e10e851a4ea0fd2d2f54c4929eacbe484f Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Tue, 1 Jun 2021 18:31:28 -0400 Subject: [PATCH] Added function to get factorial of number --- src/Algorithms.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Algorithms.rs b/src/Algorithms.rs index 3762c8b..7d42135 100644 --- a/src/Algorithms.rs +++ b/src/Algorithms.rs @@ -478,4 +478,13 @@ pub fn gcd(in1: i32, in2: i32) -> i32{ } } return num1 | num2; +} + +//Returns the factorial of the number passed in +pub fn factorial(num: i64) -> i64{ + let mut fact = 1; + for cnt in 1 ..= num{ + fact *= cnt; + } + return fact; } \ No newline at end of file