i have a problem on 3 function aside from main in factorial function and i wrote the code and the program worked perfectly on some numbers but it crashed on others this is the message i get: "MASONG11 cause a Stack Fault in module MASONG11.EXE at 0002:0076. Choose close. MASONG11 will close."
any suggestions?? please answer.. i actually needed the answer please..
here's my code:
#include <iostream.h>
int input (int n);
int factorial(int n);
int display (int n);
int main() {
int n;
input (n);
factorial (n);
display (n);
return 0;
}
int input (int n)
{
cout<<"Enter a number to find factorial: ";
cin>>n;
return n;
}
int factorial(int n)
{
if (n>1)
{
return n*factorial(n-1);
}
else
{
return 1;
}
}
int display (int n)
{
cout<<"Factoria l of "<<n<<" = "<<factorial(n) ;
return 0;
}
any suggestions?? please answer.. i actually needed the answer please..
here's my code:
#include <iostream.h>
int input (int n);
int factorial(int n);
int display (int n);
int main() {
int n;
input (n);
factorial (n);
display (n);
return 0;
}
int input (int n)
{
cout<<"Enter a number to find factorial: ";
cin>>n;
return n;
}
int factorial(int n)
{
if (n>1)
{
return n*factorial(n-1);
}
else
{
return 1;
}
}
int display (int n)
{
cout<<"Factoria l of "<<n<<" = "<<factorial(n) ;
return 0;
}
Comment