#include<iostream.h>
#include<conio.h>
void main()
{
int n;
int fact(int);
cout<<"Get Number";
cin>>n
cout<<fact(n);
}
int fact(int n)
{
if(n==0||n==1)
return 1;
else
return (n*fact(n-1);
}
Output:
Get Number
3
6
Recursive Function
A function which calls itself directly or indirectly again and again is known as the recursive function. It is very useful while construction the data structure like linked list, double linked list and trees.
#include<conio.h>
void main()
{
int n;
int fact(int);
cout<<"Get Number";
cin>>n
cout<<fact(n);
}
int fact(int n)
{
if(n==0||n==1)
return 1;
else
return (n*fact(n-1);
}
Output:
Get Number
3
6
Recursive Function
A function which calls itself directly or indirectly again and again is known as the recursive function. It is very useful while construction the data structure like linked list, double linked list and trees.
No comments:
Post a Comment