Posts

Square Pattern

#include <iostream> using namespace std ; int main (){     int n ;     cin >> n ;     int N =( 2 * n )- 1 ;     int s = 0 ;     int e = N - 1 ;     int a [ N ][ N ];         while ( n > 0 ){         for ( int i = s ; i <= e ; i ++){             for ( int j = s ; j <= e ; j ++){                 if ( i == s || i == e || j == s || j == e ){                     a [ i ][ j ]= n ;                 }             }         }         s ++;         e --;         n --;     }     for ( int i = 0 ; i < N ; i ++){         for ( int j = 0 ; j < N ; j ++){             cout << a [ i ][ j ] << " " ;         }         cout << endl ;     }       return 0 ;