C Program to reverse an array elements


In this program, You will learn how to reverse an array elements in c.


List is: 10 20 30 40 50 60

After reverse elements is: 60 50 40 30 20 10


Example: How to reverse an array elements in c

Run it Now
#include<stdio.h>

int main() {

   int arr[10], i, j, s, temp;

   printf("Enter size of an Array :");
   scanf("%d", &s);

   printf("\nEnter 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("\nAfter 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 :23 24 25 26 27
Reverse Array Elements :27 26 25 24 23