How to achieve reverse output of an array in C language?
You can achieve reversing the output of an array in C language using the following code:
#include <stdio.h>
void reverseArray(int arr[], int size) {
for (int i = size - 1; i >= 0; i--) {
printf("%d ", arr[i]);
}
printf("\n");
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
int size = sizeof(arr) / sizeof(arr[0]);
reverseArray(arr, size);
return 0;
}
In the above code, we have defined a function called reverseArray that takes an integer array and the size of the array as parameters. The function loops through the array starting from the last element and outputs each element one by one. Then, in the main function, we create an integer array called arr and calculate the size of the array. Finally, we call the reverseArray function to output the array in reverse order.