3. nested for loop implementation of drawing an empty box:
#include
int main()
{
int i, j;
/* for each of the 4 rows */
for (i = 0; i < 4; i++)
{
/* for each of the 9 columns */
for (j = 0; j < 9; j++)
{
/* if this is the top border or the botton
* border print stars all the way across */
if (i == 0 || i == 3)
{
printf("*");
}
/* for all rows that are neither the top
* nor bottom border */
else
{
/* only print a star if this is the
* the right or left border */
if (j == 0 || j == 8)
{
printf("*");
}
/* spaces need to be printed for
* the box's interior */
else
{
printf(" ");
}
}
}
printf("\n");
}
return 0;
}
4. nested for loop challenge of drawing a 4-pane window:
#include
int main()
{
int i, j;
/* for each of the 7 rows */
for (i = 0; i < 7; i++)
{
/* for each of the 9 columns */
for (j = 0; j < 9; j++)
{
/* if this is the top border the center
* row or the botton border print stars
* all the way across */
if (i == 0 || i == 3 || i == 6)
{
printf("*");
}
/* for all rows that are neither the top
* border, the center row, nor bottom border */
else
{
/* only print a star if this is the
* the right border the center column
* or left border */
if (j == 0 || j == 4 || j == 8)
{
printf("*");
}
/* spaces need to be printed for
* each pane's interior */
else
{
printf(" ");
}
}
}
printf("\n");
}
return 0;
}