C Program to find factorial of a number using the function
In this program, You will learn how to find factorial of a number using a function in c.
3! = 1 * 2 * 3
4! = 1 * 2 * 3 * 4
Example: How to find factorial of a number using a function in c.
#include<stdio.h>
int fact(int n) {
int f = 1, i;
for (i = 1; i <= n; i++) {
f = f * i;
}
return f;
}
int main() {
int n, fa;
printf("Enter a number:");
scanf("%d", &n);
fa = fact(n);
printf("Factorial is:%d", fa);
return 0;
}
Output:
Enter a number:4
Factorial is:24