Skip to content

Commit

Permalink
compute factorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Atousa committed Apr 21, 2021
1 parent 3360ca5 commit f6421b1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Recursion/Factorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Factorial {
public static int factorialRec(int n) {
if(n == 0) return 1;
if(n == 1) return 1;
return n * factorialRec(n-1);
}

public static int factorialIte(int n) {
int result = 1;
for(int i = 1; i <= n; i++)
result =result * i ;
return result;
}


public static void main(String[] args) {
System.out.println(factorialRec(4));
System.out.println(factorialIte(4));
}
}

0 comments on commit f6421b1

Please sign in to comment.