思路与一楼差不多,设第一层有a盏,那第二层就有2a盏,以此类推;
a+2a+4a+8a+16a+32a+64a+128a=(2*128-1)a=255a
所以a=3
程序如下:
#include <iostream>
using namespace std
int main()
{
int a
a=765.0/255
cout<<"最底层有"<<128*a<<"盏灯。"<<endl
return 0
}
通过以下方式登录:1、登录官网:访问灯塔教育官网,点击右上角的“登录”按钮,输入手机号或邮箱号和密码,点击“登录”即可进入灯塔教育平台;
2、/微信小程序:打开微信,搜索“灯塔教育”小程序,点击进入,输入手机号或邮箱号和密码,点击“登录”进入灯塔教育平台;
3、APP:下载灯塔教育APP,打开APP,输入手机号或邮箱号和密码,点击“登录”即可进入灯塔教育平台。
#include<stdio.h>void main()
{
int i, n = 1, m, sum = 0
while(sum <765) {
sum = 0 n++ m = n
for(i = 1i <= 8i++) { sum += m m *= 2 }
}
printf("you get it! sum = %d, n = %d\n", sum, n)
//上已经得出正确结果。
//下面是为了显示明细:
m = 3 sum = 0
for(i = 1i <= 8i++) {
sum += m
printf("i = %d, n = %d, sum = %d\n", i, m, sum)
m *= 2
}
}
//程序运行后,显示如下:
you get it! sum = 765, n = 3
i = 1, n = 3, sum = 3
i = 2, n = 6, sum = 9
i = 3, n = 12, sum = 21
i = 4, n = 24, sum = 45
i = 5, n = 48, sum = 93
i = 6, n = 96, sum = 189
i = 7, n = 192, sum = 381
i = 8, n = 384, sum = 765
Press any key to continue
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)