Reputation: 21
My GCC compiler giving me warning:
power.c: In function ‘main’: power.c:9:36: warning: implicit declaration of function ‘power’ [-Wimplicit-function-declaration] 9 | printf("%d \t %d \t %d \n", i+1, power(2,i), power(-6,i));
whereas I have clearly declared implicit for the power function, which I give in the following code:
#include <stdio.h>
int main(){
int i;
printf("%s \t %s \t %s \n", "Powers", "of 2", "of -6");
for (i = 0; i < 10; ++i)
printf("%d \t %d \t %d \n", i+1, power(2,i), power(-6,i));
return 0;
}
int power(int base, int n){
int i, p;
p = 1;
for (i=0; i <= n; ++i)
p = p * base;
return p;
}
Upvotes: 0
Views: 866
Reputation: 3774
You need to forward declare your power
function before you call it:
int power(int base, int n);
int main(){
int i;
printf("%s \t %s \t %s \n", "Powers", "of 2", "of -6");
for (i = 0; i < 10; ++i)
printf("%d \t %d \t %d \n", i+1, power(2,i), power(-6,i));
return 0;
}
Or, you could just move the definition of power
before main
.
Upvotes: 3