My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

factorial using recursion

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
int fact(int);
void main()
{
  clrscr();
  int n;
  cout<<"enter the number: ";
  cin>>n;
 cout<<"factorial of "<<n<<" is ";
 cout<<fact(n);
  getch();
}
int fact(int x)
{
  int p;
  if(x>0)
 { p=x*fact(x-1);
  return p; }
  else
  return 1;
}

1 comments:

Anonymous said...
This comment has been removed by a blog administrator.