{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2_Questions_6_4_nested_loops-1

# 2_Questions_6_4_nested_loops-1 - printf""...

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

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; }

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

View Full Document
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++ ) {

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf("*"); printf("\n"); } printf("\n"); } 29. Predict the output. s = 0; x = 5; y = 2; while (x > y) { for ( i = 1; i < x; i++ ) s += i; x -= y; } printf("%d\n", s); 2 i i < 3 j j < 3 Output x x > y i i < 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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern