Settings | Sign in | Sign up

There is currently 1 post.

2014决赛试题\c本科B

Floor 1 巨大八爪鱼 5/5/16 19:07

标题:年龄巧合

    小明和他的表弟一起去看电影,有人问他们的年龄。小明说:今年是我们的幸运年啊。我出生年份的四位数字加起来刚好是我的年龄。表弟的也是如此。已知今年是2014年,并且,小明说的年龄指的是周岁。

    请推断并填写出小明的出生年份。

    这是一个4位整数,请通过浏览器提交答案,不要填写任何多余的内容(比如,他表弟的出生年份,或是他们的年龄等等)

 【代码】
#include <stdio.h>

int main(void)
{
    int age = 0;
    int birthyear = 2014;
    int a, b, c, d;
    while (age < 100)
    {
        a = birthyear / 1000;
        b = birthyear % 1000 / 100;
        c = birthyear % 100 / 10;
        d = birthyear % 10;
        if (a + b + c + d == age)
            printf("%d\n", birthyear);
       
        birthyear--;
        age++;
    }
    return 0;
}

【结果】
2006
1988

【答案】
1988

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
©2010-2025 Purasbar Ver3.0 [Mobile] [Desktop]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported license.