# How to swap even elements to the right side and odd elements to the left side in an 1D array

2
by Traitor

What programming language are you using

c++

Log in to add a comment

by Traitor

What programming language are you using

c++

Log in to add a comment

The Brainliest Answer!

#include<conio.h>

void main()

{

clrscr();

int a[50],n,i;

cout<<"Enter limit : ";

cin>>n;

cout<<"Enter elements of the array\n";

for(i=0;i<n;i++)

cin>>a[i];

for(i=0;i<n;i++)

{

if(a[i]%2==0)

{

for(j=i+;j<n;j++)

{

if(a[j]%2!=0)

{

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

}

cout<<"Array after arrangement \n";

for(i=0;i<n;i++)

cout<<a[i]<<endl;

getch();

}

int temp,a[20],b[20];

for(i=0,m=0;i<n;i++)

for(j=n;j>0;)

{

if(a[i]%2==0)

{

b[m]==a[i];

m++;

}

else

{

b[j]=a[i];

j--;

}

}}

i think this would work