代码文本:
#include "stdio.h"
#include "time.h"
int main(int argc,char *argv[]){
char s[19];
int y,t,ty;
time_t lt;
printf("Please enter your ID number...\n");
if(scanf("%18s",s)==1){
for(t=0;s[t];t++);
if(t==18){
for(t=0;s[t];t++)
if((s[t]<'0' || s[t]>'9') && (s[17]&0xDF)!='X'){
printf("Input error, exit...\n");
return 0;
}
sscanf(s+6,"%4d",&y);
printf("\nThe year %d you were born is ",y);
if(!(y%4==0 && y%100 || y%400==0))
printf("not ");
ty=localtime(&(lt=time(NULL)))->tm_year+1900-y;
printf("a leap year.\nYou're %d year(s) old...\n",ty);
}
else
printf("Input error, exit...\n");
}
else
printf("Input failed, exit...\n");
return 0;
}