远望巍巍塔七层,红光点点倍加增,共灯三百八十一,试问尖头几盏灯。
来源:百度知道 编辑:UC知道 时间:2024/06/09 22:20:22
怎么样编写程序?
已经编译运行确认:
#include<stdio.h>
#include<conio.h>
int N=7;
void main()
{
int i=0,j=0,count=0,total=0;
for(i=1;;i++)
{
for(j=1;j<=N;j++)
{
if(j==1) count=i;
else count*=2;
total += count;
}
if(total==381)
{
printf("尖头%d盏灯",i);
break;
}
else total=0;
}
getch();
}