Coding:-
#include<iostream.h>
int fact (int n)
{
int value=1;
if(n==1)
return(value);
else
{
value=n*fact(n-1);
return(value);
}
}
main()
{
int fact(int);
int f, n;
cout<<"enter a number=";
cin>>n ;
f=fact(n);
cout<<"factorial of a number is ="<<f<<"\n";
}
Output:-
No comments:
Post a Comment