import java.io.*;
class Factorial
{
public static void main(String args[])
{
int no,fact;
fact=1;
try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter number whose Factorial is to be found : ");
no=Integer.parseInt(obj.readLine());
while(no > 0)
{
fact=fact*no;
no=no-1;
}
System.out.println("FACTORIAL of a given number is : "+fact);
}
catch(Exception e)
{}
}
}
Output:
Enter number whose Factorial is to be found : 12
FACTORIAL of a given number is : 479001600
class Factorial
{
public static void main(String args[])
{
int no,fact;
fact=1;
try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter number whose Factorial is to be found : ");
no=Integer.parseInt(obj.readLine());
while(no > 0)
{
fact=fact*no;
no=no-1;
}
System.out.println("FACTORIAL of a given number is : "+fact);
}
catch(Exception e)
{}
}
}
Output:
Enter number whose Factorial is to be found : 12
FACTORIAL of a given number is : 479001600
No comments:
Post a Comment