What is the method for reversing the output of a one-di…

The method for reverse output of a one-dimensional array can be achieved through the following steps:

  1. Create a one-dimensional array.
  2. Output each element of the array starting from the last one and continuing until the first one.

Here is an example code using a for loop:

#include <stdio.h>

#define SIZE 5

int main() {
    int arr[SIZE] = {1, 2, 3, 4, 5};
    
    printf("原始数组:");
    for(int i = 0; i < SIZE; i++) {
        printf("%d ", arr[i]);
    }
    
    printf("\n逆序输出:");
    for(int i = SIZE - 1; i >= 0; i--) {
        printf("%d ", arr[i]);
    }
    
    return 0;
}

Output result:

原始数组:1 2 3 4 5 
逆序输出:5 4 3 2 1 
bannerAds