C Program to reverse an Array
This below C program will just reverse the given array. This can be done by using for loop. When you run the below program it will ask you the size of the array and then the program will ask you to enter the numbers. after that the array reverse logic will happen. after that the array in reverse order will be printed.
#include<stdio.h>
#include<conio.h>
int main(){
int n, i, j, temp, a[100];
printf("Enter the Array Size");
scanf("%d",&n);
printf("Current Array Element");
for ( i = 0 ; i < n ; i++ )
scanf("%d",&a[i]);
if( n%2 == 0 )
i = n/2 - 1;
else
i = n/2;
for ( j = 0 ; j < i ; j++ ){
temp = a[j];
a[j] = a[n -j - 1];
a[n-j-1] = temp;
}
printf("Array in Reverse Order
");
for( i = 0 ; i < n ; i++ )
printf("%d
",a[i]);
getch();
return 0;
}
