Here is the code and the error found, please correct it and let the program count from 0 to 1000.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <stdio.h>
#include <stdlib.h>
int main() {
int list[1002], inserted = 0, operations = 0;
for (int i = 0; i <= 499; i++) {
list[i] = i;
}
for (int i = 500; i <= 999; i++) {
list[i] = i + 1;
}
for (int i = 999; inserted == 0; i--) {
operations = operations + 1;
if (list[i] > 500) {
list[i + 1] = list[i];
} else {
list[i + 1] = 500;
inserted = 1;
}
}
printf("%d ", list[i]);
printf("Inserted 500 in %d operations\n", operations);
return 0;
}