2_Questions_6_4_nested_loops-1

2_Questions_6_4_nested_loops-1 -...

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

View Full Document Right Arrow Icon
CIS 15AG Questions 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; void printTriangle(int height) { int row; int col; return; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
CIS 15AG Questions Chapter 6: Repetitions (nested loops) 27. Predict the output. int i; int j; for ( i = 1; i <= 3; i++ ) { for ( j = 1; j <= 3; j++ ) printf("%d %d\n", i, j); printf("\n"); } 28. How many asterisks and '\n's are displayed? (A). for ( k = 1; k <= 5; k++ ) printf("*"); printf("\n"); (B). for ( j = 1; j <= 10; j++ ) { for ( k = 1; k <= 5; k++ ) printf("*"); printf("\n"); } printf("\n"); (C). for ( i = 1; i <= 3; i++ ) { for ( j = 1; j <= 10; j++ ) { for ( k = 1; k <= 5; k++ )
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf(&quot;*&quot;); printf(&quot;\n&quot;); } printf(&quot;\n&quot;); } 29. Predict the output. s = 0; x = 5; y = 2; while (x &gt; y) { for ( i = 1; i &lt; x; i++ ) s += i; x -= y; } printf(&quot;%d\n&quot;, s); 2 i i &lt; 3 j j &lt; 3 Output x x &gt; y i i &lt; x s Output 5 CIS 15AG Questions Chapter 6: Repetitions (nested loops) 30. Write a program fragment that uses nested loops to produce the output 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 int row; int col; 31. Write a program fragment that uses nested loops to produce the output 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 int row; int col; 3 CIS 15AG Questions Chapter 6: Repetitions (nested loops) 32. Write a program fragment that uses nested loops to produce the output 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 int row; int col; 33 * . Write a program fragment that uses nested loops to produce the output 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9 6 7 8 9 7 8 9 0 1 8 9 0 1 2 9 0 1 2 3 int row; int col; 4...
View Full 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

2_Questions_6_4_nested_loops-1 -...

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

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