谁能告诉我为什么我不能这样做?
它没有编译,我知道我一定是错了。
我正在尝试打印 2 的幂,但我就是不能这样做。
谁能帮帮我?这是我写的代码。我在 Linux 上使用 gcc。
#include <stdio.h>
#include <math.h>
int main() {
int power;
printf("Powers of 2:\n");
{int i;
for(i = 0; i < 30; i++){
power = pow(2,i);
printf("%s%i %s %i %s","2^",i,"=",power,"\n");
}
}
return 0;
}
最佳答案
gcc foo.c -lm -o foo
你已经像这样编译了。 'm' 是数学库
关于c - C 中 for 循环中的 Pow() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26601705/