0% found this document useful (0 votes)
3 views1 page

Nested Loop Programming Exercises

The document outlines a series of programming exercises involving nested loops. It includes tracing a program that prints a pattern of stars, creating a rectangle of stars based on user input, generating a table of numbers, printing a number pattern, and finding Pythagorean triplets based on user input. Each exercise provides sample inputs and expected outputs to guide implementation.

Uploaded by

enter.user4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Nested Loop Programming Exercises

The document outlines a series of programming exercises involving nested loops. It includes tracing a program that prints a pattern of stars, creating a rectangle of stars based on user input, generating a table of numbers, printing a number pattern, and finding Pythagorean triplets based on user input. Each exercise provides sample inputs and expected outputs to guide implementation.

Uploaded by

enter.user4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Homework – Nested Loop

1. Trace the following programs. Assume that SIZE has the value 5.
Program Memory Output
for (int i = 1; i < SIZE; i++) {
for (int j = SIZE; j >= i; j--)
{
[Link](“*”);
}
[Link]();
}

2. Write a program that draws a rectangle with stars, given the number of rows
and columns.

Sample Input Sample Output


Enter # of rows: 5 ****
Enter # of columns: 4 ****
****
****

3. Write a program that will prompt user for two numbers x & y then output a
table of numbers with x rows and each of the rows lists number from 1 to y,
separated by a space.

Sample Input Sample Output


Enter x: 5 1 2 3 4 5 6
Enter y: 6 1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6

4. Write a program using nested loops that prints the following pattern.
1
12
123
1234
12345

5. Three positive integers a, b, and c with a < b < c form a Pythagorean triplet if
a2 + b2 = c2. For example 3, 4, 5 form a Pythagorean triplet since 3 2 + 42 = 52.
Write a program that first prompts the user for a positive integer and then
finds and prints all Pythagorean triplets whose largest member is less than or
equal to that integer.

You might also like