Here we are going to reverse the elements of an array using C program.
Reverse the Elements of an Array :
ArrayRverse.c
#include<stdio.h>
int main(void)
{
int i,j,temp;
int arr[10] = {1,2,3,4,5,6,7,8,9,10};
// Reversing the elements using temp variable.
for(i=0,j=9; i<j; i++,j--){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
printf("After reversing, the array is : ");
for(i=0; i<10; i++){
printf("%d ",arr[i]);
}
printf("\n");
return 0;
}
Output:
Terminal
After reversing, the array is: 10 9 8 7 6 5 4 3 2 1
Happy Learning 🙂