课后作业 结果不对 请大佬指点一下
#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("%11u\n", sum);
printf("%11u\n", weight);
return 0;
}
自己打出来结果为4294967295
源代码
#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;
}
结果18446744073709551615
请大佬指点一下
认真一点
printf("%11u\n", sum);
printf("舍罕王应该给予达依尔%llu粒麦子!\n", sum); 改的地方再注释中了
#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);//这里换成两个小写的L 下边那个也是哦~
printf("%llu\n", weight);
return 0;
}
{:5_103:} 谢谢大佬
页:
[1]