import java.util.*;
class factorial
{
public static void main (String arg[])
{
Scanner in = new Scanner (System.in);
int a,b=1;
System.out.print ("\n\t Enter the number = ");
a=in.nextInt();
while (a>0)
{
b*=a;
--a;
}
System.out.println ("\n\t Factorial = "+b);
}
}
Note:
First of all computer will check the condition of while loop. If it is true then it will
multiply b by a. After that it will decrease the value of a by 1 and repeat the same task. This
will continue until a=0. When a=0 the loop will be broken and the next statement to it will
be executed.
i have a question how we will take different numbers and then it will print the factorial of all the numbers that are entered from the user
ReplyDelete