C program to calculate factorial using function
Posted by Spider on 5:31 AM
#include <stdio.h> long factorial(int); int main() { int number; long fact = 1; printf("Enter a number to calculate it's factorial :"); scanf("%d", &number); printf("Factorial of %d = %d",number,result); return 0; } long factorial(int n) { int c; long result = 1; for (c = 1; c <= n; c++) result = result * c; return result; }
/*
Output :
Enter a number to calculate it's factorial : 5
Tags
C Basics