C program to find the factorial of a number using function
C program for how to find factorial of a number using function
by Krishna viswambharan
Posted on 01 Sep 2017 Category: C
Views: 1682
Edited on 05 Sep 2017
C program to find factorial using function
In the last sections we have seen that how to find the factorial of a number using loops. Now we will see, how to find the factorial of a number using function in C.
sample code for the same is given as
#include <stdio.h>
#include <conio.h>
int factorial(int); //function prototype or declaration
void main()
{
int n,f;
printf(“enter the number :”);
scanf(“%d”,&n);
f=factorial(n); //function call
printf(“factorial of %d=%d”,n,f);
getch();
}
int factorial(int a) // function definition
{
int j,fac=1;
for(i=1;i<=a;i++)
{
fac=fac*i;
}
return(fac);
}
output