如果它符合算法,它应该有一个输出真,如果它不,输出应该是假的。知道哪里出错了吗?
我试过了
1586455534096 ; output : false(fail)
49927398716 ; output : true (ok)
984697300577 ; output : false (fail)
代码
#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
int n,num[100],prod[100],remainder,sum,total;
scanf("%s", str);
for(n=0;n<100;n++)
{
if(str[n]==0) break;
num[n] = str[n] - '0';
if(n%2!=0)
{
prod[n]=num[n]*2;
sum=0;
while(prod[n]>=10)
{
remainder=prod[n]%10;
sum=sum+remainder;
prod[n]=prod[n]/10;
}
num[n]=sum;
}
total = total + num[n];
}
if(total%10==0)
printf("true\n");
else
printf("false\n");
return 0;
}