|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 天之蔲 于 2020-11-5 12:14 编辑
- #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;
- }
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- unsigned long long sum = 0; //定义三个高精度数,分别代表 总和(sum),当前格子内的麦子(temp),和重量(weight)
- unsigned long long temp;
- unsigned long long weight;
- int i; //循环变量
- for (i = 0; i < 64; i++) //循环,i从零到64
- {
- temp = pow(2, i); //temp等于2的i次方
- sum = sum + temp; //将temp加到sum中去
- }
- //到这一步,循环结束,sum等于2+4+8+16+32+64+128+.......+2^64
- weight = sum / 25000; //除以25000得到总重量
- //输出
- printf("舍罕王应该给予达依尔%llu粒麦子!\n", sum);
- printf("如果每25000粒麦子为1kg,那么应该给%llu公斤麦子!\n", weight);
- return 0;
- }
复制代码
|
|