PROGRAM
//Program to reverse a single dimensional array without using another array
# include <iostream>
using namespace std;
int main()
{
int a[5],i,sum=0;
cout<<"INPUT THE ARRAY ELEMENTS:\n";
for(i=0;i<5;i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
cout<<"REVERSED ARRAY:\n";
for(i=0;i<2;i++)
{
a[i]=a[i]+a[4-i];
a[4-i]=a[i]-a[4-i];
a[i]=a[i]-a[4-i];
}
for(i=0;i<5;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
return 0;
}
OUTPUT
//Program to reverse a single dimensional array without using another array
# include <iostream>
using namespace std;
int main()
{
int a[5],i,sum=0;
cout<<"INPUT THE ARRAY ELEMENTS:\n";
for(i=0;i<5;i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
cout<<"REVERSED ARRAY:\n";
for(i=0;i<2;i++)
{
a[i]=a[i]+a[4-i];
a[4-i]=a[i]-a[4-i];
a[i]=a[i]-a[4-i];
}
for(i=0;i<5;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<endl;
}
return 0;
}
OUTPUT