|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <math.h>
int main()
{
unsigned long long sum = 0;
unsigned long long temp;
unsigned long long weight;
int i;
for (i=0; i < 64; i++)
{
temp = pow(2, i);
sum = sum + temp;
}
weight = sum / 25000;
printf("舍罕王应该给予达依尔%llu粒麦子!\n", sum);
printf("如果每25000粒麦子是1KG,那么应该给%llu公
斤麦子!\n", weight);
return 0;
}
运行结果是:
gcc test1.c && ./a.out
/tmp/cctGNsA7.o:在函数‘main’中:
test1.c:(.text+0x36):对‘pow’未定义的引用
collect2: 错误:ld 返回 1
复制小甲鱼的答案运行也是这个结果,这是为什么呢?各位大哥
第一个作业:
#include <stdio.h>
#include <math.h>
int main()
{
unsigned int result;
result = pow(1, 2) + pow(2, 3) + pow(3, 4) + pow(4, 5) + pow(5, 6);
printf("结果是:%u\n", result);
return 0;
}
运行结果就正常:
gcc test.c && ./a.out
结果是:16739
本帖最后由 jackz007 于 2022-10-21 11:19 编辑
因为你使用了数学库 libm.so,所以,需要在编译的时候告诉编译器,否则,它不知道调用的 pow() 到底该找谁落实。
|
|