Recursion:
It is a technique that makes a method calls itself repeatedly until some base condition is satisfied.
for more on recursion, Visit:
http://en.wikipedia.org/wiki/Recursion
Source Code:
/*
Program to find a factorial of number using recursion
Author: sourcecodesonline.blogspot.com
It is a technique that makes a method calls itself repeatedly until some base condition is satisfied.
for more on recursion, Visit:
http://en.wikipedia.org/wiki/Recursion
Source Code:
/*
Program to find a factorial of number using recursion
Author: sourcecodesonline.blogspot.com
*/
#include<stdio.h>
int factorial(int);
{
int no,i,fact;
printf("\nEnter the number: ");
scanf("%d",&no);
fact=factorial(no); //function to return the factorial the parameter passed
printf("\nThe factorial of number %d is %d\n",no,fact);
return 1;
}
//recursive function to find factorial of a number
int factorial(int n)
{
if(n==0)//base condition
return 1;
else
{
return n * factorial(n-1);
}
}
EmoticonEmoticon