Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee60ff2

Browse files
committed
factorial using recursion
1 parent dc7a255 commit ee60ff2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/binod/RecursionFactorial.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package binod;
2+
import java.util.Scanner;
3+
public class RecursionFactorial {
4+
//Q. Find the factorial of n number
5+
public static void main(String[] args) {
6+
Scanner scanner = new Scanner(System.in);
7+
System.out.println("Enter n number");
8+
int n = scanner.nextInt();
9+
printFactorial(n, 1);
10+
}
11+
public static void printFactorial(int n, int fac) {
12+
if(n==1){
13+
System.out.println(fac);
14+
return;
15+
}
16+
fac*=n;
17+
printFactorial(n-1, fac);
18+
}
19+
}

0 commit comments

Comments
 (0)