C Program to Reverse an Array Elements

Reversing an array in C involves swapping the elements of the array in a way that the first element becomes the last, the second becomes the second-to-last, and so on. Here’s a simple C program that reverses an array

Program :

#include<stdio.h>
void main(){
int i,length;
printf(“Enter the Length of array : “);
scanf(“%d”,&length);
int arr[length];
printf(“Enter elements into the array:”);
for(i=0;i<length;i++){
printf(“arr[%d] :”,i);
scanf(“%d”,&arr[i]);
}
printf(“\nOriginal array: \n”);
for ( i = 0; i < length; i++) {
printf(“%d “, arr[i]);
}
printf(“\nArray in reverse order: \n”);
for ( i = length-1; i >= 0; i–) {
printf(“%d “, arr[i]);
}
return 0;
}

Output :

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights