Program:-
import java.util.Scanner;
class group{
public static void main(String angt[]){
Scanner data = new Scanner(System.in);
double num,i,fat=1;
// Reading a number
System.out.println("Enter a number to find factorial");
num=data.nextDouble();
for(i=1;i<=num;i++)
fat=fat*i;
System.out.println("Factorial of the number is:"+fat);
}
}
Output:-
Enter a number to find factorial
4
Factorial of the number is:24.0
Output:-
Enter a number to find factorial
0
Factorial of the number is:1.0
Output:-
Enter a number to find factorial
15
Factorial of the number is:1.307674368E12
import java.util.Scanner;
class group{
public static void main(String angt[]){
Scanner data = new Scanner(System.in);
double num,i,fat=1;
// Reading a number
System.out.println("Enter a number to find factorial");
num=data.nextDouble();
for(i=1;i<=num;i++)
fat=fat*i;
System.out.println("Factorial of the number is:"+fat);
}
}
Output:-
Enter a number to find factorial
4
Factorial of the number is:24.0
Output:-
Enter a number to find factorial
0
Factorial of the number is:1.0
Output:-
Enter a number to find factorial
15
Factorial of the number is:1.307674368E12
Leave reply
Add your comments here