Boundary Condition(s):
2<= N <= 1000
1<= Each integer value <= 10^5
Input Format:
The first line contains N.
The Second line contains N integer separated by a space.
Example Input/Output:
Input:
7
22 43 56 51 68 50 28
Output:
56 43 22 51 50 68 28
Explanation:
There are two even integer pairs in the given integers.
The 1st even integer pair is 22 and 56. After swapping, the integers become 56 43 22 51 68 50 28.
The 2nd even integer pair is 68 and 50. After swapping, the integers become 56 43 22 51 50 68 28.
#include<stdio.h>
#include <stdlib.h>
void printevenswap(int arr[],int n)
{
for(int i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
}
int main()
{
int n,i,j,fl=0;
scanf("%d",&n);
int a[1001];
for(i=0;i<n;i++)
{
scanf("%d ",&a[i]);
}
int co=0;
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
fl+=1;
if(fl==1)
{co=i;}
else if(fl==2)
{
int sort=a[co];
a[co]=a[i];
a[i]=sort;
fl=0;
co=0;
}
}
}
printevenswap(a,n);
}
Just Give Your Feedback ConversionConversion EmoticonEmoticon