wrong result calculation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

wrong result calculation

hi, when i run this code which is taking a number and calculating it's factorial, when i try and enter a number more than 16 it gives me a false negative number and sometimes zero. why is this and how to fix? but i just wanna know why it does this really. here's the code: #include <iostream> using namespace std; int fact(int n){ if (n==1){ return 1; } else { return n*fact(n-1); } } int main(){ int a; cin >>a; cout << fact(a); }

17th Aug 2020, 5:54 PM
Youssef Hossam
Youssef Hossam - avatar
0 Answers