所以我在 C: 中有这段代码
#include <stdio.h>
int main() {
int a[9], number_of_elements;
printf("Enter 10 numbers: \n");
for (int i = 0; ((i < 10) && (a[i] != 0)); i++) {
scanf_s("%d", &a[i]);
if (a[i] == 0) {
number_of_elements = i;
break;
}
if (a[i] != 0) {
number_of_elements = i + 1;
}
}
printf("There is %d elements.\n", number_of_elements);
return 0;
}
正如你所看到的,我必须在数组中输入最多 10 个元素,或者在输入 0 时停止输入,之后我必须打印该数组的所有元素以及数组有多少个元素。我对除了打印数组的所有元素之外的所有内容进行了排序,任何人都可以帮助我如何做到这一点?
最佳答案
您应该使用另一个 for 循环,例如:
for(i=0;i<number_of_elements;i++)
{
printf("%d ",a[i]);
}
关于c - 输入所有数组后,如何在 C 中打印数组的所有元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43366803/