问题描述:生日蜡烛
某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛。
现在算起来,他一共吹熄了236根蜡烛。
请问,他从多少岁开始过生日party的?
请填写他开始过生日party的年龄数。
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
int sum;
for(int y=1;y<100;y++)
{
sum =0;
// t=y;要放在这里!!
t=y;
for(int i=0;i<100;i++){
// t=y;不能放在这里,要放在上一个for循环那里
// t=y;
sum+=t;
if(sum==236)
{
cout<<y<<"岁开始"<<endl<<i<<endl;
cout<<"现在"<<t<<"岁"<<endl;
cout<<sum<<endl;
}
t++;
}
}
return 0;
}
分析:这题其实很简单。。。因为t=y;放错了位置!!(欲哭无泪)