import java.util.Scanner;
class FactorialWhile{
public static void main(String args[]){
int fact=1,num,i=1;
System.out.println("Enter the number:");
Scanner in=new Scanner(System.in);
num=in.nextInt();
while(i<=num){
fact=fact*i;
i++;
}
System.out.println("factorial of given number is "+fact);
} }
class FactorialWhile{
public static void main(String args[]){
int fact=1,num,i=1;
System.out.println("Enter the number:");
Scanner in=new Scanner(System.in);
num=in.nextInt();
while(i<=num){
fact=fact*i;
i++;
}
System.out.println("factorial of given number is "+fact);
} }
No comments:
Post a Comment
Please post your comments. Your comments make us to write more programs for you.