Write a program to two show Factorial of a number
#include<iostream.h>
int rec(int);
main()
{
int a ,fact;
cout<<"enter any number";
cin>>a;
fact=rec(a);
cout<<fact;
}
int rec(int x)
{
int f;
if (x==1)
return(1);
else
f=x*rec(x-1);
return(f);
}
int rec(int);
main()
{
int a ,fact;
cout<<"enter any number";
cin>>a;
fact=rec(a);
cout<<fact;
}
int rec(int x)
{
int f;
if (x==1)
return(1);
else
f=x*rec(x-1);
return(f);
}
Comments
Post a Comment