ronith
5/29/2018 - 8:27 PM

Segregate even and odd numbers - Set 2

#include <iostream>
using namespace std;

int main(){
    int n;
    cout << "No.of elements:";
    cin >> n;
    int a[n];
    cout << "\nEnter the array elements:";
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    int b[n];
    int i = 0, j= 0, k = 0;
    while(i<n){
        if (a[i]%2 == 0){
            b[j] = a[i];
            j++;}
        else{
            b[n-1-k] = a[i];
            k++;}
    i++;
    }
    for (int i = 0; i < n; i++){
        cout << a[i] << "  ";
    }
    cout << "\n";
    for (int i = 0; i < n; i++){
        cout << b[i] << "  ";
    }
}