Well, I'm doing a basic code in C, I'm not very good with this language, I'm learning it, although I've already seen it not used much. It consists of doing the power operation through recursion. The problem is in the output when the power is greater than 10
// Input: // 6 20
// Output: // - 1190133760
The code:
#include <stdio.h>
int potencia(A, N){
int x;
if(N == 0){
return 1;
}
return A*potencia(A, N-1);
}
int main(){
int A, N;
scanf("%d %d", &A &N);
printf("%d\n", potencia(A, N));
}
As you can see, the output is a totally absurd number, but I do not know why or how it happens. Can someone explain to me and if possible explain what I have to do to generate the right output?