Generate minimum sum sequence of integers with even elements greater | C ++ implementation of above approach ; Function to print the required sequence ; arr [ ] will hold the sequence sum variable will store the sum of the sequence ; If sum of the sequence is odd ; Print the sequence ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void make_sequence ( int N ) { int arr [ N + 1 ] , sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( i % 2 == 1 ) arr [ i ] = 1 ; else arr [ i ] = 2 ; sum += arr [ i ] ; } if ( sum % 2 == 1 ) arr [ 2 ] = 3 ; for ( int i = 1 ; i <= N ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int N = 9 ; make_sequence ( N ) ; return 0 ; }