I wrote some simple code in Python, JavaScript and C. I found that the Python and JavaScript results are the same, but C gives me another -wrong- result and I can't understand what is the error.
C code:
int fact(int n){
if(n==1){
return 1;
}else{
return (n*fact(n-1));
}
}
int main(void){
printf("%i \n",fact(13));
}
JS code:
function fact(n){
if (n==1){
return (1);
}else{
return (n*fact(n-1));
}
}
console.log(fact(13));
Python code:
def fact(n):
if(n == 0):
return 1
else:
return n * fact(n - 1)
print(fact(13))
Can you explain?