1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
using namespace std;
void fillBoard(char b[],int ROWS,int COLS,char ch)
{
for (int row = 0;row < ROWS;row++)
{
for (int col =0; col < COLS; col++)
{
b[col+COLS*row] = ch;
}
}
}
void drawBoard(char b[],int ROWS, int COLS)
{
for (int row = 0;row < ROWS;row++)
{
cout << row+1 << " " ;
for (int col =0; col < COLS; col++)
{
cout << b[col+row*COLS] << " ";
}
cout << endl;
}
cout << endl;
}
int main()
{
char board1[6*5];
char board2[9*4];
char board3[7*2] = {'1','2','3','4','5','6','7','8','9','A','B','C','D','E'};
fillBoard(board1,6,5,'.');
drawBoard(board1,6,5);
fillBoard(board2,9,4,'*');
drawBoard(board2,9,4);
drawBoard(board3,7,2);
return 0;
}
|