a program to print the factorial of a number given by the user using a recursive function
Answers
Answered by
0
Answer:
Java
import java.util.*;
public class factorial{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number for finding factorial");
int num=in.nextInt();
System.out.println(fact(num));
}
public static int fact(int num) {
if(num==1)
return 1;
else
return fact(num-1); // recursion
}
}
This is the program to find factorial using recursion in Java
Similar questions