C Program - Calculate the Factorial of a Number Using Recursion
#include <stdio.h>
long factorial(int n) {
if(n == 0)
return 1;
else
return n * factorial(n - 1);
}
int main() {
int num;
printf("Enter a positive integer: ");
scanf("%d", &num);
printf("Factorial of %d = %ld\n", num, factorial(num));
return 0;
}
Enter a positive integer: 5
Factorial of 5 = 120
Comments
Loading comments...