鱼C论坛

 找回密码
 立即注册
查看: 2043|回复: 4

[已解决]课后作业 结果不对 请大佬指点一下

[复制链接]
发表于 2021-6-6 12:02:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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("%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


请大佬指点一下
最佳答案
2021-6-6 12:07:10

认真一点

printf("%11u\n", sum);
printf("舍罕王应该给予达依尔%llu粒麦子!\n", sum);
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-6-6 12:07:10 | 显示全部楼层    本楼为最佳答案   

认真一点

printf("%11u\n", sum);
printf("舍罕王应该给予达依尔%llu粒麦子!\n", sum);
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-6-6 12:18:02 | 显示全部楼层
改的地方再注释中了

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5.          unsigned long long sum = 0;
  6.          unsigned long long temp;
  7.          unsigned long long weight;
  8.          int i;


  9.          for(i=0; i < 64; i++)
  10.          {
  11.                      temp = pow(2, i);
  12.                      sum = sum + temp;
  13.          }
  14.          weight = sum / 25000;
  15.          printf("%llu\n", sum);//这里换成两个小写的L 下边那个也是哦~
  16.          printf("%llu\n", weight);
  17.          return 0;
  18. }
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-6-6 12:36:20 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-6 15:53:33 | 显示全部楼层
谢谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-7 01:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表