Created
February 20, 2022 09:36
-
-
Save Blinhy0131/551e3790a75c3a9524a58c3fce2c8b45 to your computer and use it in GitHub Desktop.
14.身分證求檢查碼
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
W10023273 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
void main(){ | |
int a[10],b,nem,ans=0,check_nem,a_n=0; | |
char c; | |
FILE *fpr=fopen("c.txt","r"); | |
fscanf(fpr,"%c%d",&c,&b); | |
nem=(int)c-55; | |
a[0]=nem/10; | |
a[1]=nem%10; | |
a[2]=b/10000000; | |
a[3]=b%10000000/1000000; | |
a[4]=b%1000000/100000; | |
a[5]=b%100000/10000; | |
a[6]=b%10000/1000; | |
a[7]=b%1000/100; | |
a[8]=b%100/10; | |
a[9]=b%10; | |
for(int i=10;i>=1;i--){ | |
if (i==10){ | |
check_nem=1; | |
}else{ | |
check_nem=i; | |
} | |
ans=ans+a[a_n]*check_nem; | |
a_n++; | |
} | |
ans=10-(ans%10); | |
printf("%c%d%d%d%d%d%d%d%d\n",c,a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]); | |
printf("Ans=%c%d%d%d%d%d%d%d%d%d\n",c,a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],ans); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment