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.

Shopping Basket
Verified by MonsterInsights