Print N distinct numbers following the given operations | C ++ implementation to Print N distinct numbers ; Function to print the required array ; Check if number is a multiple of 4 ; Printing Left Half of the array ; Printing Right Half of the array ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool printArr ( int n ) { if ( n % 4 == 0 ) { for ( int i = 1 ; i <= n / 2 ; i ++ ) cout << i * 2 << ' ▁ ' ; for ( int i = 1 ; i < n / 2 ; i ++ ) cout << i * 2 - 1 << ' ▁ ' ; cout << n + n / 2 - 1 << ' ' ; } else cout << " - 1" ; } int main ( ) { int n = 22 ; printArr ( n ) ; return 0 ; }