I am trying to print:
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
11 2048
12 4096
13 8192
14 16384
15 32768
16 65536
17 131072
18 262144
19 524288
20 1048576
21 2097152
22 4194304
23 8388608
24 16777216
25 33554432
26 67108864
27 134217728
28 268435456
29 536870912
30 1073741824
31 -2147483648
32 0
Thsi is my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int powerof2(int n);
int main(void)
{
for (int n=0; n<32 ;n++)
{
printf("n 2^n\n");
printf("%d %d\n", n, powerof2);
}
}
int powerof2(int n)
{
int power=1;
for(int j=0;j<n;++j)
{
if (j == 0)
power = 1;
else
power *= 2;
}
return power;
}
I have to use function - int powerof2(int n).
But it gives me an error:
power1.c: In function ‘main’:
power1.c:11: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘int ()(int)’
power1.c:11: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘int ()(int)’