C program to find factorial of a number using function
C program to find factorial of a number
by Krishna
Posted on 27 Jul 2018 Category: C
Views: 2922
C program to find factorial of a number
Below shows the C program to find factorial of a number using function.
#include <stdio.h>
long factorial(int);
int main()
{
int number;
long fact = 1;
printf("Enter a number :");
scanf("%d", &number);
printf("Factorial of %d = %ld\n", number, factorial(number));
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for (c = 1; c <= n; c++)
result = result * c;
return result;
}
OUTPUT
