3_Answers_6_4_nested_loops-1

3_Answers_6_4_nested_loops-1 - CIS 15AG Answers Chapter 6:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Answers Chapter 6: Repetitions (nested loops) 25. Write a fragment of code that prints 3 rows of 5 asterisks each. ***** ***** ***** 26. Write a function that prints n rows of asterisks. The first row has 2 asterisks, the second 4, the third 6, and so on. Below is the pattern for n = 5 ** **** ****** ******** ********** 1 int i; for ( i = 1; i <= 5; i++ ) printf( "*" ); printf( "\n" ); for ( i = 1; i <= 5; i++ ) printf( "*" ); printf( "\n" ); for ( i = 1; i <= 5; i++ ) printf( "*" ); printf( "\n" ); int i; int row; for ( row = 1; row <= 3; row++ ) { for ( i = 1; i <= 5; i++ ) printf( "*" ); printf( "\n" ); } void printTriangle(int height) { int row; int col; int width; for ( row = 1; row <= height; row++ ) { width = 2 * row ; for ( col = 1; col <= width; col++ ) printf( "*" ); printf( "\n" ); } return; } void printTriangle(int height) { int row; int col; for ( row = 1; row <= height; row++ ) { for ( col = 1; col <= 2 * row ; col++ ) printf( "*" ); printf( "\n" ); } return; } // No
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/02/2011 for the course CIS 15BG taught by Professor Staff during the Spring '10 term at DeAnza College.

Page1 / 4

3_Answers_6_4_nested_loops-1 - CIS 15AG Answers Chapter 6:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online