输入身份证号
输出出生日期,年龄,性别
例如:输入221023200110101315
输出2001年10月10日
年龄
性别
请你看这个帖子下面的 “相关推荐”, 你就可以找到答案了。
截取 第7位到 第14位 就是 年月日
参考如下:
#include <stdio.h>
#include <string.h>
int main(){
char code[19] = "221023200110101315";
char year[5], month[3], day[3];
strncpy(year, code + 6, 4);
year[4] = '\0';
strncpy(month, code + 10, 2);
month[2] = '\0';
strncpy(day, code + 12, 2);
day[2] = '\0';
printf("%s年%s月%s日", year, month, day);
return 0;
}
#include<stdio.h>
int main(){
int i;
char s[18];
scanf("%s",s);
for(i=0;'\0'!=s[i];++i){
}
printf("年份为%c%c%c%c 月份为%c%c 日为%c%c",s[6],s[7],s[8],s[9],s[10],s[11],s[12],s[13]);
}
##第二种方法
#include <stdio.h>
int main(){
int i;
char s[18];
scanf("%s",s);
for(i=6;i<=13;++i){
printf("%c",s[i]);
}
}