WAP to find factorial of a number.
1 year ago
OOP Java
Compile code:
import java.util.Scanner;
public class Factorial{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int num=sc.nextInt();
int i=1,fact=1;
while(i<=num)
{
fact=fact*i;
i++;
}
System.out.println("Factorial of the number: "+fact);
}
}
Output:
Dipti KC
Jan 8, 2023