1
Well, I’m doing a basic code in C, I’m not very good with this language, I’m learning it, although I’ve seen it not used much. It consists of doing the power operation through recursion. The problem lies 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 can be seen, the output is a totally absurd number, but I do not why and how it happens anyone can explain to me and if possible explain what I have to do to generate the right output?
The problem has nothing to do with power, but with the fact that you are bursting the numerical capacity of the type
int
.– Bacco