Programming Examples

Write a program to input an integer and find its factorial.


Write a program to input an integer and find its factorial. Factorial of a number is the product of all natural numbers till that number. For example factorial of 5 is 120 since 1×2×3×4×5=120.

Solution

class Factorial
{
	public static void main(Strign arr[])
	{
		Scanner sc=new Scanner(System.in);
		int i,f=1,n;
		System.out.println("Enter a number:");
		n=sc.nextInt();
		for(i=1;i<=n;i++)
		{
		f=f*i;
		}
		System.out.println("Factorial="+f);
	}
}
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad