我不知道为什么这段代码是错误的:
int sum = 0;
// take sum of every other digit starting with second-to-last and add to sum variable
for (int i = length; i > 0; i -= 2)
{
sum += cardString[i];
printf("%c | %i\n", cardString[i], sum);
}
假设长度为 15,“cardString”字符串为 378282246310005,以下是该程序的输出:
| 0
0 | 48
0 | 96
3 | 147
4 | 199
2 | 249
2 | 299
7 | 354
老实说,我不知道为什么会这样。有任何想法吗?