Skip to content

Instantly share code, notes, and snippets.

@Blinhy0131
Created February 20, 2022 09:36
Show Gist options
  • Save Blinhy0131/551e3790a75c3a9524a58c3fce2c8b45 to your computer and use it in GitHub Desktop.
Save Blinhy0131/551e3790a75c3a9524a58c3fce2c8b45 to your computer and use it in GitHub Desktop.
14.身分證求檢查碼
W10023273
#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