Print N distinct numbers following the given operations | 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
function printArr ( n ) { if ( n % 4 == 0 ) { for ( var i = 1 ; i <= n / 2 ; i ++ ) document . write ( i * 2 + ' ' ) ; for ( var i = 1 ; i < n / 2 ; i ++ ) document . write ( i * 2 - 1 + ' ' ) ; document . write ( n + n / 2 - 1 + ' ' ) ; } else document . write ( " " ) ; } var n = 22 ; printArr ( n ) ;