|
|
back to boardwhat the first test? Posted by ejjjik 29 Dec 2011 13:25 #include <iostream> #include <iomanip> //#include <conio.h> using namespace std; #define size 105 int main() { //const int size = 105; int mas[size][size]; int xSize; cout << "Input array size: "; cin >> xSize; if ( xSize <= 100 && xSize >=1 ) { //заполняемые элементы int ch = 1; // правая половина + диагональ; top right corner + main diagonal for ( int f = 0; f < xSize; f++ ) {
for( int i = 0, j = xSize - 1, d = f; d >= 0; i++, d-- ) { mas[ i ][ j - d ] = ch++; }
} // левая половина; left down corner for ( int f = 1; f < xSize; f++ ) {
for( int i = f, j = 0, d = 0; i < xSize; i++, d++ ) { mas[ i ][ j + d ] = ch++; }
} //output array for ( int i = 0; i < xSize; i++ ) { for ( int j = 0; j < xSize; j++ ) { cout << setw(4) << mas[i][j]; } cout << endl;
} } //_getch(); return 0; } |
|
|