它應掃描10個整數,然後向後顯示它們,將偶數除以2,但只是顯示它們而不分割。爲什麼我的程序不會將偶數除以二?
ES:
10 9 8 7 6 5 4 3 2 1 ==> 1 2 3 2 5 3 7 4 9 5
但礦的作用: 10 9 8 7 6 5 4 3 2 1 == > 1 2 3 4 5 6 7 8 9 10
#include <stdio.h>
int main(void)
{
int a[10];
for(int i = 0; i < 10; i++)
scanf("%d", &a[i]);
for (int i = 0; i < 10; i++) {
if (a[i] % 2 == 0) {
a[i] = a[i]/2; i++;
}
else
i++;
}
for(int i = 9; i > -1; i--)
printf("%d\n", a[i]);
return 0;
}
[如何調試小鐠(https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) –