C++ Program To Find Factorial Of A Number, Using Recursive Function

Leave a Comment
/*Finding Factorial of a number using Recursion(or Recursive Function)
Recursive Function : Recursive function is a type of function which calls itself in Function Definition Code Segment until a terminating condition reached. In the following program "fact( )" is a recursive function.*/

#include<iostream.h>
#include<conio.h>

int fact(int n)               //Defining a recursive function for n! calculation 
{
int t;
if(n==1)
return (1);
else
t=n*fact(n-1);
return (t);
}
 
void main()
{
clrscr();
int n;
printf("\nEnter the number");
scanf("%d",&n);
printf("\n factorial=%d",
fact(n));
getche();
}

0 comments: