Wipro NLTH Coding Solve | Odd Even Online Game | Codewindow.in

You are playing an online game. In the game, a list of N numbers is given. The player has to arrange the numbers so that all the odd numbers of the list come after the even numbers. Write an algorithm to arrange the given list such that all the odd numbers of the list come after the even numbers.

Input
The first line of the input consists of an integer num, representing the size of the list (N). The second line of the input consists of N space-separated integers representing the values of the list.

Output
Print N space-separated integers such that all the odd numbers of the list come after the even numbers.

Constraints
NA

Example

Input :
8
10 98 3 33 12 22 21 11

Output:
10 98 12 22 3 33 21 11

Explanation:
All the even numbers are placed before all odd numbers.

#include "stdio.h"
int main()
{
    int n;
    scanf("%d", &n);
    int i,a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        printf("%d ",a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]%2!=0)
        printf("%d ",a[i]);
    }
}

Also Checkout

Recent Posts

Leave a Comment

Your email address will not be published. Required fields are marked *