2 n will be the number of iterations
for ( int t = 0 ; t < ( 2 * n - 1 ) ; t ++ ) { int t1 = t ; if ( t1 >= n ) { mode ++ ; t1 = n - 1 ; it -- ; lower ++ ; } else { lower = 0 ; it ++ ; } for ( int i = t1 ; i >= lower ; i -- ) { if ( ( t1 + mode ) % 2 == 0 ) { cout << ( mat [ i ] [ t1 + lower - i ] ) << endl ; } else { cout << ( mat [ t1 + lower - i ] [ i ] ) << endl ; } } } return 0 ; }