请教一下这程式码~~~
主要有两行看不懂~为何---sum+=(a[i]-'0')*(8-i);
if(code==(a[7]-'0')) 後面要加-'0'呢?
程序如下:
#include<stdio.h>
main()
{
char number[9];
printf("enter the uniform number:");
scanf("%s",number);
if(valid(number));
printf("the number %s is valid\n",number);
else
printf("the number &s is invalid\n",number);
}
int valid(char a[])
{
int i,sum,code;
sum=0;
for(i=0,i<=6;i++)
sum+=(a[i]-'0')*(8-i);
code=sum%10;
if(code==(a[7]-'0'))
return (1);
else
return (0);
}