求助大神,编程实现输入一个人的年龄,计算并输出其出生年份

如题所述

#include <stdio.h>
#include <time.h>

int main( )
{
 int year,x;
 time_t nowtime;
 struct tm *timeinfo;
 time( &nowtime );
 timeinfo = localtime( &nowtime );

 year = timeinfo->tm_year + 1900;
 while (1)
 {
 printf("请输入你的年龄:");
scanf("%d",&x);

 
 if (x>0&&x<=100)
 {
  printf("你的出生年份是:%d\n", year-x);
 }
 else if(x<=0)
 {
 printf("你还没有出生吗?\n");
 }
 else
 {
printf("大于100岁的人不管\n");
}

 }


 return 0;
}

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网