C program to reverse an array-Iterative method

Write a program to reverse an array
Iterative way:
1) Initialize low and high indexes.
low = 0, high = n-1
2) In a loop, swap arr[low] with arr[high] and change low and high as follows.
low =low +1;high = high– 1

#include<stdio.h>

main()

{

int a[20],low,high,i,temp,n;

printf("Enter Number of array element:\n");
scanf("%d",&n);

printf("Enter array element:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}

low=0;
high=n-1;

while(low<high)
{
temp=a[low];
a[low]=a[high];
a[high]=temp;
low++;
high--;
}

printf("Enter array element in Reverse:\n");
for(i=0;i<n;i++)
{
 printf("%d\t",a[i]);
}
printf("\n");
}

Related Posts