#include<stdio.h> int factorial(int num){ if(num==1){ //Termination condition for recursion return 1; } else{ return num*factorial(num-1); //Recursive call to evaluate recursively factorial of n-1 } } int main(){ int number,result; printf("Enter the number to find factorial\n"); scanf("%d",&number); //user input for number result=factorial(number); //call to factorial printf("Factorial of %d is %d\n",number,result); return 0; } ipput:5 output:120
Search Program on this blog
Monday, 17 August 2015
C program for factorial of a number with recursion
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment