Monday, July 27, 2009

Help writing a C programming function?

Here's the question:





Write a function that creates the following pattern, given the height (# of rows) and width (asterisks per row):





***************


***************


***************


***************





Not sure how to begin. This is from the 'repetition' chapter about do loops and such.





Thank you!

Help writing a C programming function?
Okay, this should be straightforward. First, write code to just print one bar of the proper length. Use a loop. Then, when this is working, you can put all that code inside another loop to repeat the bars.





The trick here is to break things down into pieces. You start with an easy piece, and work up from there.
Reply:write a function that returns void and accepts two "int" type parameters (ex. int height, int width)





write for loops that loops for the # of times that height specifies, within the height loop write another for loop that outputs the '*' to the display for the number of iterations that width specifies, probably also need to output a newline character for each of the height loop iterations





ex.





void PrintAsterisks(int height, int width)


{





/* add for loops here */








}

lady palm

No comments:

Post a Comment