C program to calculate factorial using recursion
Posted by Spider on 5:40 AM
#include<stdio.h> long factorial(int); int main() { int n; long f; printf("Enter an integer to find factorial :"); scanf("%d", &n); if (n < 0) printf("Negative integers are not allowed.\n"); else { f = factorial(n); printf("Factorial od %d = %d", n, f); } return 0; } long factorial(int n) { if (n == 0) return 1; else return(n * factorial(n-1)); }
/*
Output :
Enter an integer to find factorial : 5Factorial od 5 = 120
*/
Tags
C Basics