Skip to main content

Recursion in C. To find the factorial of any number

//Any function which call itself is called recursion in c
//A termination condition is imposed on such functions to stop them executing copies of themselves forever.
// example to find factorial of number

#include<stdio.h> int factorial(int number) { if (number==0||number==1) { return 1; } else { return(number*factorial(number-1)); } } int main() { int a=5,b=6; do { int num; printf("Enter the number you want factorial of:-\n"); scanf("%d",&num); printf("The factorial of %d is %d\n",num,factorial(num)); } while(a<b); return 0; }

Comments