# Classwork 24: nested for loops revisited

## Objectives

more practice with nested for loops.

## The Assignment

Write a program that asks the user for the length and height of a rectangle. Your program draws a rectangle of that size and a smaller rectangle inside it. The smaller rectangle has half the size of the larger rectangle. Sample runs of your program might look like:

```PT[274]% ./a.out
Enter # of rows: 12
Enter length of each row: 12
*  *  *  *  *  *  *  *  *  *  *  *
*                                *
*                                *
*        *  *  *  *  *  *        *
*        *              *        *
*        *              *        *
*        *              *        *
*        *              *        *
*        *  *  *  *  *  *        *
*                                *
*                                *
*  *  *  *  *  *  *  *  *  *  *  *
PT[275]%
```

```PT[275]% ./a.out
Enter # of rows: 8
Enter length of each row: 16
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
*                                            *
*           *  *  *  *  *  *  *  *           *
*           *                    *           *
*           *                    *           *
*           *  *  *  *  *  *  *  *           *
*                                            *
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
PT[276]% ./a.out
```

The starting point of your program is: nested6.c.

## Notes

• The outer rectangle is already printed for you, so how hard can this be?

• Leave the numbers printed inside the rectangle until the very end. Then replace the number with 3 spaces.

• You need to figure out the "coordinates" of the inner rectangle. The coordinates of the top-left corner of the inner rectangle is roughly 1/4 of the length and height of the outer rectangle.

• Once you figure out the locations of the 4 corners of the inner rectangle, you are pretty much done.

## Submit

Use the script command to record several sample runs of your program. Demonstrate that your program works for different size rectangles as well as non-square rectangles. Don't forget to exit from script. Then, submit your program and sample run as usual:

```submit cs104_chang cw24 nested.c
submit cs104_chang cw24 typescript
```