|
|
发表于 2017-6-21 01:49:37
|
显示全部楼层
0:
#include<stdio.h>
#include<math.h>
int main()
{
int sum;
sum = pow(1,2) + pow(2,3) + pow (3,4) + pow(4,5);
printf("总和为:%d",sum);
return 0;
}
1:
#include<stdio.h>
#include<math.h>
int main()
{
int i = 0;
unsigned long long int sum = 0;
unsigned long long int weight;
unsigned long long int temp;
for (i=0; i<64; i++)
{
temp = pow(2,i);
sum += temp;
}
weight = sum/25000;
printf("舍罕王应该给予达依尔%llu粒麦子!\n如果每25000粒麦子为1kg,那么应该给%llukg麦子!\n", sum, weight);
return 0;
}
一开始循环体内写成:sum += pow(2,i);
然后就各种错误,把printf内 %llu %l64u都用过了都是计算错,然后试了好久,才发现不能直接写:printf("%d", pow(2,4)),必须写 temp = pow(2,4),然后能 printf("%d",temp);
吃亏吃大发了,写这么小的代码想了大半天。 |
|