题目如下:
蓝桥杯生日蜡烛C语言
题目:生日蜡烛
某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛。
现在算起来,他一共吹熄了236根蜡烛。
请问,他从多少岁开始过生日party的?
请填写他开始过生日party的年龄数。
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。
代码如下:
#include<stdio.h>
int main()
{
int a = 0;
int b = 0;
int c = 0;
for (a = 1; a < 100; a++)
{
for (b = a; b < 100; b++)
{
int sum = 0;
for (c = a; c <=b; c++)
sum = sum + c;
if (sum == 236)
{
printf("%d %d", a, b);
}
}
}
return 0;
}
运行结果如下:
26岁开始过生日,现在33岁了
答案26