1D array program to swap first half with second half
NikhilMTomy:
Which is the language
Answers
Answered by
11
#include...
.....
void main()
{
clrscr();
int n,a[20];
cin>>n;
for( int i=0;i<n;i++)
cin>>a[i];
for( i=0,int j=n;i<=n/2;i++,j--)
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
getch() ;
}
.....
void main()
{
clrscr();
int n,a[20];
cin>>n;
for( int i=0;i<n;i++)
cin>>a[i];
for( i=0,int j=n;i<=n/2;i++,j--)
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
getch() ;
}
Answered by
6
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,a[20],temp;
cin>>n;
for( int i=0;i<n;i++)
cin>>a[i];
for( i=0,int j=n/2;j<n;i++,j++)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
cout<<"Displaying the new array \n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch() ;
}
Similar questions