Hi, why does the two functions factorial and factorial2 only return the right factorial if the input is 12 or less ?
#include "iostream"
using namespace std;
int factorial(int n){
if (n==0){
return 1;
}
else{
return n*factorial(n-1);
}
}
int factorial2 ( int x ) {
int p = 1;
for ( int i = 2; i <= x; i++ ) {
p = p * i;
}
return p;
}
int main(void){
int b = 0;
do{
cout << "Enter a number: " << endl;
cin >> b;
cout << b << "! = " << factorial(b) << " or " << factorial2(b) << endl;
}while(b>0);
}