I'm learning C function construction and I'm trying to make an exponent function with two arguments: base & exponent.
#include <stdio.h>
#include <stdlib.h>
int power(int a,int b){
int c;
int i;
c=1;
for(i=1;i<=b;++i){
c=c*a;
}
return c;
}
int main(){
int nice=power(5,20);
printf("answer =%d , and size is=%d ", nice, sizeof(nice));
return 0;
}
When I execute the program, it gives me the following output:
answer =1977800241 ,and size is=4
EDIT:
But when I execute power(5,2)
, it gives a perfect result of 25.