For the last element
for ( int i = 0 ; i < vertices ; i ++ ) { if ( vertex_set [ i ] == 0 && j == 0 ) { cout << " ( " << ( i + 1 ) << " , ▁ " ; j ++ ; } else if ( vertex_set [ i ] == 0 && j == 1 ) cout << ( i + 1 ) << " ) STRNEWLINE " ; } }