Online Compiler C

#include <stdio.h> enum { SIZE = 10 }; int main() { int Z[SIZE]; int F[SIZE]; int count_Z = 0, count_F = 0; int n; for (int i = 0; i < SIZE; i++) { scanf("%d", &n); if (n > 0) { Z[count_Z] = n; count_Z++; } else if (n < 0) { F[count_F] = n; count_F++; } } for (int i = 0; i < count_Z; i++) { printf("%d ", Z[i]); } for (int i = 0; i < count_F, i++) { printf("%d ", F[i]); } return 0; }
这段代码的功能是:读取10个整数,将正数存入数组Z,负数存入数组F,然后先输出所有正数,再输出所有负数。

代码中存在一个语法错误:

- 第22行的for循环条件中使用了逗号运算符 `count_F, i++`,这会导致循环条件始终为 `i++` 的值,而不是正确的比较。应该使用分号分隔条件部分。

另外,代码逻辑上需要注意:

- 如果输入中有零,它不会被存入任何数组,也不会被输出。这是否符合预期需要确认。