五、A 公司 1 月人事資料檔案如下表,請撰寫下列程式片段。(2 題,共 15 分)
bool check_dit(int n){ //輸入6碼數字
int tmp=n/10, sum=0;
while(tmp){
sum+=tmp%10;
tmp/=10;
}
sum%=10; //第6碼
if(sum==(n%10)) return true;
else return false;
}


boolean check_dit(int num[ ] ) {
int len = num.length;
checking = num[len-1]%10;
if (len != 6)
return false
else
temp_sum = 0;
for(int i =0; i < (len-2); i++)
temp_sum += num[i];
if(temp_sum == checking)
return true;
else
return false;
}
#include <math.h>
#include <stdbool.h>
bool check_id(int emp_id)
{
int emp_id_Chk[6];
int Sum_Chk=0;
for(int y=5;y>=0;--y)
{
emp_id_Chk[y]=(emp_id/(int)pow(10,5-y))%10;
}
for(int z=0;z<5;++z)
{
Sum_Chk+=emp_id_Chk[z];
}
if((Sum_Chk%10)==emp_id_Chk[5])
return true;
else
return false;
}