0
I wrote a code for solving a factor-adding problem. When I created the recursive function for the factorial calculation, I used in the function call the decrease operator --
followed by the number, and this generated an error in the answer. What is the reason for the operator to change the answer? Below is the code.
#include <iostream>
#include <cstdio>
using namespace std;
long long int factorial(long long int num){
if(num == 1 || num == 0) return 1;
return num*factorial(--num);
}
int main() {
long long int M, N;
while(scanf("%lli %lli", &M, &N)!=EOF)
cout << factorial(M)+factorial(N) << endl;
return 0;
}
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero