在C语言中,可以使用循环语句来输出数组的元素。下面是两种常见的方式:
使用for循环:#include <stdio.h>int main() { int arr[5] = {1, 2, 3, 4, 5}; int i; for (i = 0; i < 5; i++) { printf("%d ", arr[i]); } return 0;}输出结果:
1 2 3 4 5使用while循环:#include <stdio.h>int main() { int arr[5] = {1, 2, 3, 4, 5}; int i = 0; while (i < 5) { printf("%d ", arr[i]); i++; } return 0;}输出结果:
1 2 3 4 5无论使用for循环还是while循环,都需要使用一个变量来作为数组的索引,利用这个索引来逐个输出数组的元素。

