Computer Science, asked by Traitor, 1 year ago

1D array program to swap first half with second half


NikhilMTomy: Which is the language

Answers

Answered by arakkalvaishnav
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() ;








   

Traitor: Thnx
Answered by aalaparunp66okp
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