Printing a simple pattern using 2D array row and column of characters
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: none
To do: Printing a simple pattern using 2D array row and column of characters
To show: How to nest two for loops constructing the 2D array and then prints the elements
/* Nesting two for loop */
#include <stdio.h>
// function prototype
void DrawBox(int, int);
void main(void)
{
// function call, with row = 10, column = 25...
DrawBox(10, 25);
}
void DrawBox(int row, int column)
{
int col;
// row, execute outer for loop, start with the preset value and decrement until 1
for( ; row > 0; row--)
{
// column, execute inner loop, start with preset col, decrement until 1
for(col = column; col > 0; col--)
// print #....
printf("#");
// decrement by 1 for inner loop, go to new line for new row...
printf("\n");
}
// decrement by 1 for outer loop...then repeat...
}
Output example:
#########################
#########################
#########################
#########################
#########################
#########################
#########################
#########################
#########################
#########################
Press any key to continue . . .