////////////////////////////////////////////////////////////////////////// // name.c // // // // Purpose // // ======= // // This program generates a "cross pattern" of 1's (amongst 0's) on // // a square board for a given size of the board (the board // // is represented by a 2-D array, a C++ built-in array) // // // // Author Creation Date // // ====== ============= // // AY 22 Oct 2003 // // // // Input/Output // // ============ // // The program expects the board size (of type int) as input // // The program produces the board with a "cross pattern" of ones // // // ////////////////////////////////////////////////////////////////////////// #include using namespace std; int main() { const int maxSize=10; // absolute max size of the board int board[maxSize][maxSize]; // array declaration int boardSize; // actual size of the board cout << "Enter board size (0< size<=10):"; cin >> boardSize; cout << endl; int row; int col; // fill the board with a cross pattern of ones for (row=0; row < boardSize; row++) { // i is the number of row for (col=0; col< boardSize; col++) { // j is the no. of column if (row==col || row+col==boardSize-1) { board[row][col]=1; } else { board[row][col]=0; } } // end or row } // output the contents of the board cout << "Here is your patterned board:" << endl; for (row=0; row < boardSize; row++) { // i is the number of row for (col=0; col< boardSize; col++) { // j is the no. of column cout << board[row][col] << " "; } // end or row cout << endl; } cout << "End of Board" << endl; exit(0); return 0; } // end main()