C Program to reverse an array elements
In this program, You will learn how to reverse array elements in c.
List is: 10 20 30 40 50 60
After reverse elements: 60 50 40 30 20 10
Example: How to reverse array elements in c.
#include<stdio.h>
int main() {
int arr[10], i, j, s, temp;
printf("Enter size of an array:");
scanf("%d", &s);
printf("Enter array elements:");
for (i = 0; i < s; i++) {
scanf("%d", &arr[i]);
}
j = s - 1;
for (i = 0; i < j; i++) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
j--;
}
printf("After reverse array elements:");
for (i = 0; i < s; i++) {
printf("%d ", arr[i]);
}
return 0;
}
Output:
Enter size of an array:5
Enter array elements:10 20 30 40 50
After reverse array elements:50 40 30 20 10