[Courses] Chapter 4 Exercise 4-2 SPOILER

Mary linuxchix at puzzling.org
Mon Feb 18 17:07:06 EST 2002


On Sun, Feb 17, 2002 at 07:03:07PM -0500, Wendy Galovich wrote:
> char a; /* the character which will be printed */
> int x; /* number of times "a" will be printed across a row */
> int y; /* number of rows to print */
> 
> then I can use a loop referencing y to control the number of times the row is 
> printed?

Yes, and use x to check whether it is time to go onto the next row.

> Also, in order to print the block for different x and y variables, 
> without recompiling, the input values need to come from outside of the 
> program itself (from the keyboard or an input file), correct? 

Yes. Or you could write it as a function:

        print_e(int height, int width) {
                /* function here */
        }

and write a test driver file, for example:

        int main() {
                print_e(6,4);
                print_e(1, 10);
                /* etc */
        }

Yes, you will have to recompile the test driver to add or change tests,
but it still illustrates the concepts nicely, and it is good to write
tests for your code :-)

-Mary.

-- 
Mary
<mary at puzzling.org>



More information about the Courses mailing list