以下是我的程序代码:
#include <time.h>
#include <stdio.h>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime ); //获取当前时间
int CurrentYear=timeinfo->tm_year+1900;
int BirYear=0;
int a=0;
printf("符合出生年份之和等于他的年龄的出生年份有:\n");
for(BirYear=0;BirYear<=CurrentYear;BirYear++)
{
int count=0;
a=BirYear;
while(a!=0)
{
count+=a%10;
a/=10;
}
if(count==(CurrentYear-BirYear))
printf("%d\n",BirYear);
}
return 0;
}
运行结果:
希望对你有所帮助。