Quote:
Originally Posted by cerebrum View Post
#include<iostream>
#include<conio.h>

using namespace std;

int fac(int n)
{
int c;
c = n*fac(n-1);
cout<<c;
}


int main()
{
fac(3);
}


tried this also ! tried with getch( ) also !


for any recursion function, termination condition should be.
your code should be like..
Code:
#include<iostream>
#include<conio.h>

using namespace std;

int fac(int n)
{
int c;
if(n<=1)
 return 1;
else
 return(n*fac(n-1));
 
}


int main()
{
  int factVal=0;
  factVal = fac(3);
  cout<<"Fatorial of 3 is "<<factVal<<endl;
  getch();
  return 0;
}