wwx1005 2022-12-25 19:56 采纳率: 100%
浏览 139
已结题

c语言身份证号码看是否成年了

c语言编写程序,输入身份证号码看是否成年了。
已知某人身份证号码的指针char *idno,编写函数,判断该人是否超过十八岁,如果是,返回1,否则返回0.
int judge(char *idno)

  • 写回答

1条回答 默认 最新

  • 流比 2022-12-25 20:16
    关注
    
    #include <time.h>
    
    int is_adult(const char *idno) {
        // 将身份证号码的前 6 位转换为出生年份
        int year = (idno[6] - '0') * 1000 + (idno[7] - '0') * 100 + (idno[8] - '0') * 10 + (idno[9] - '0');
        // 获取当前年份
        time_t current_time = time(NULL);
        struct tm *tm = localtime(&current_time);
        int current_year = tm->tm_year + 1900;
        // 如果当前年份减去出生年份大于 18,则表示该人已经成年
        return current_year - year > 18;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月10日
  • 已采纳回答 1月2日
  • 创建了问题 12月25日