C++ Program to reverse a single dimensional array without using another array [DEVCPP/GCC]

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

C++ Program to reverse a single dimensional array without using another array with output

Share this

Related Posts

FIND US ON FACEBOOK!