Question
Find the factorial of a number in a given range using recursion
ENTER THE LOWER NUMBER:1
ENTER THE UPPER NUMBER:25
Factorial of numbers
1:1
2:2
3:6
4:24
5:120
6:720
7:5040
8:40320
9:362880
10:3628800
11:39916800
12:479001600
13:6227020800
14:87178291200
15:1307674368000
16:20922789888000
17:355687428096000
18:6402373705728000
19:121645100408832000
20:2432902008176640000
21:51090942171709440000
22:1124000727777607680000
23:25852016738884976640000
24:620448401733239439360000
25:15511210043330985984000000
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
import java.math.BigInteger;
class FactorialOfNumber
{
public static BigInteger Factorial(long num)
{
if(num==1)
{
return BigInteger.valueOf(1);
}
else
{
return Factorial(num-1).multiply(BigInteger.valueOf(num));
}
}
public static void main(String args[])
{
long lowerRange=0,upperRange=0,i=0;
BigInteger fac=new BigInteger("1");
Scanner sc=new Scanner(System.in);
System.out.print("ENTER THE LOWER NUMBER:");
lowerRange=sc.nextLong();
System.out.print("ENTER THE UPPER NUMBER:");
upperRange=sc.nextLong();
System.out.println("Factorial of numbers");
for(i=lowerRange;i<=upperRange;i++)
{
if(i>0)
{
fac=Factorial(i);
System.out.println(i+":"+fac);
}
}
}
}
Coding Store
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale