In this tutorial, we are going to write a C Program to find the factorial of a number using a function in C Programming with practical program code and step-by-step full complete explanation.

C Program to find the factorial of a number using a function


C Program to find the factorial of a number using a function

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

void main()
{
	int a,f;
	int fact(int);

	clrscr();

	printf("Enter a number: ");
	scanf("%d",&a);
	f=fact(a);
	printf("factorial = %d",f);

	getch();
}

int fact(int x)
{
	int fact=1, i;
	for(i=x;i>=1;i--)
	fact=fact*i;

	return(fact);
}


Output

 
Enter a number: 5
Factorial = 120