A program to initialize a 1-D array and store the values in the reverse order.

 

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int a[5],i,j=4,temp;

for(i=0;i<5;i++)
{
cout<<"Enter a number: ";
cin>>a[i];
}

for(i=0;i<3;i++)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
j--;
}

cout<<"\nArray: ";
for(i=0;i<5;i++)
cout<<a[i]<<" ";

getch();
}

 

< Back