#include<time.h>
int?main()
{
int?get_age(int?birth[]);
char?id[19];
int?birth[8],age=0;
printf("輸入身份證:");
scanf("%s",id);
for(int?i?=?0;?i?<?8;?i++){
birth[i]=id[6+i]-'0';
}
printf("年齡為:%d",get_age(birth));
return?0;
}
int?get_age(int?birth[]){
int?age?=?0;
time_t?timep;
struct?tm?*p;
time(&timep);
p?=gmtime(&timep);
age?+=?1900+p->tm_year?-?(birth[0]*1000?+?birth[1]*100?+?birth[2]*10?+birth[3]);
int?tmp?=?1+p->tm_mon?-?(birth[4]*10?+birth[5]);
if(tmp?==?0){
if((p->tm_mday?-?(birth[6]*10?+birth[7]))?<?0){
age?--;
}
}else?if(tmp?<?0){
age?--;
}
return?age;?
}