身份证号码验证c语言
时间: 2023-12-02 17:40:39 浏览: 268
嵌入式身份证系统查询
以下是一个用C语言实现身份证号码验证的例子:
```c
#include <stdio.h>
#include <string.h>
int main()
{
int N;
scanf("%d", &N);
char id[20];
int weight[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char check[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
int flag = 1;
for (int i = 0; i < N; i++) {
scanf("%s", id);
int sum = 0;
for (int j = 0; j < 17; j++) {
if (id[j] < '0' || id[j] > '9') {
flag = 0;
break;
}
sum += (id[j] - '0') * weight[j];
}
if (!flag) {
printf("ID number %s is invalid.\n", id);
flag = 1;
continue;
}
int z = sum % 11;
if (id[17] != check[z]) {
printf("ID number %s is invalid.\n", id);
continue;
}
printf("ID number %s is valid.\n", id);
}
return 0;
}
```
阅读全文