recursive function
// using copy of the function inside the function is called recursion or recursive function
#include <stdio.h>
int factorial(int n);
int main()
{
int n,fact;
printf("enter no of which u want factorial:");
scanf("%d",&n);
fact=factorial(n);
printf("factorial of %d is %d",n,fact);
return 0;
}
int factorial(int n)
{
if(n==0 || n==1)
{
return 1;
}
else
{
return n*factorial(n-1);
}
}
Comments
Post a Comment