# C Program to Find Factorial of a Number

Hello Readers 🙂 Hope you are getting valuable posts. If you have any query or want to know about any program, Let Me Know, I’ll love to help you out. And Keep Learning.

Now I am going to write a program to find the factorial of a number. Factorial of a number is the multiplication of all numbers lower than it and greater than zero as factorial of 5 will be 5*4*3*2*1=120.

Let’s Make The Program ►►

#include<stdio.h>
#include<conio.h>

void main()
{
int num, fact=1, i;
printf("Enter Number to find it's factorial");
scanf("%d",&num);

for ( i=num ; i >= 1 ; i--,num-- )
fact=fact*num;

printf("Factorial of the number is %d\n",fact);

getch();
}

Explanation : For example we want to find the factorial of 5 we know that the factorial of 5 will be 5*4*3*2*1=120. So in the for loop we initialize i=num; to start from 5 and decrement it every after the statement after for loop executed by 1 using i–; also we decrement the variable num as for when i=5, num is also equals to 5 then after multiply with fact, we decrement it, now the num will be 4 and so on.

Remmeber while declaring the variable fact, initialize it with 1 otherwise any garbage value will be multiply with the number.