Factorial Pogram in C

In this section you will learn how to find a factorial of given number. In mathematic term factorial of non-negative integer, is multiplication of all integers.

Factorial Program

Example of factorial number.

Formula:- n! = n x (n - 1) x (n - 2) x .... x 1

5! = 5 x 4 x 3 x 2 x 1 = 120.

4! = 4 x 3 x 2 x 1 = 24.

How program will work?

Program of factorial number in c.


	#include<stdio.h>
	#include<conio.h>
		
	//FACTORIAL PROGRAM
	void main()
	{
		int n,i,fact=1;
		clrscr();
		printf("ENTER A NUMBER:- ");
		scanf("%d",&n);

		for(i=1; i<=n; i++)
		{
			fact=fact*i;
		}
			
		printf("FACTORIAL OF %d IS:- %d",n,fact);
		getch();
	}
	

Output:


	ENTER FIRST NUMBER:- 5
	FACTORIAL OF 5 IS:- 120

Post Your Comment