蓝桥杯--生日蜡烛

题目:

某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛。
现在算起来,他一共吹熄了236根蜡烛。
请问,他从多少岁开始过生日party的?
请填写他开始过生日party的年龄数。

C语言代码:

#include<stdio.h>
#include<stdlib.h>
int main(){
    for(int i=10;i<200;i++){
        int sum=i;
        for(int j=i+1;j<200;j++){
            sum=sum+j;
            if(sum>236)
            break;
            if(sum==236){
                printf("%d",i);
                return 0;
            }
            
        }
    }
    return 0;
}

结果为:26

原文地址:https://www.cnblogs.com/pythonbigdata/p/8511344.html