Find the good permutation of first N natural numbers | C ++ implementation of the approach ; Function to print the good permutation of first N natural numbers ; If n is odd ; Otherwise ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int printPermutation ( int n ) { if ( n % 2 != 0 ) cout << -1 ; else for ( int i = 1 ; i <= n / 2 ; i ++ ) cout << 2 * i << " ▁ " << 2 * i - 1 << " ▁ " ; } int main ( ) { int n = 4 ; printPermutation ( n ) ; return 0 ; }