Source Code :
//program to accept number and find its factorial
import java.util.*;
public class factorial
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int no,fact=1,i;
System.out.print("\n Enter no to find its factorial : ");
no=sc.nextInt();
for(i=1;i<=no;i++)
{
fact=fact*i;
}
System.out.println("\nFactorial of "+no+" is "+fact);
}
}
Output Screen :
//program to accept number and find its factorial
import java.util.*;
public class factorial
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int no,fact=1,i;
System.out.print("\n Enter no to find its factorial : ");
no=sc.nextInt();
for(i=1;i<=no;i++)
{
fact=fact*i;
}
System.out.println("\nFactorial of "+no+" is "+fact);
}
}
Output Screen :
No comments:
Post a Comment