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

Nested Loops

The document provides five programming exercises that involve using loops to create various patterns and tables based on user input. The tasks include printing a square grid, an addition table, a triangle pattern, a character matrix, and a multiplication chart. Each exercise includes examples and hints for implementation using nested loops.

Uploaded by

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

Nested Loops

The document provides five programming exercises that involve using loops to create various patterns and tables based on user input. The tasks include printing a square grid, an addition table, a triangle pattern, a character matrix, and a multiplication chart. Each exercise includes examples and hints for implementation using nested loops.

Uploaded by

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

🔹 1.

Grid Printer
Ask the user for a number n and print a square grid of * with size n × n.
Example:
Input: 3
Output:
***
***
Hint: Use two loops — one for rows and one for columns.

🔹 2. Addition Table
Ask the user for a number n. Print a table where each cell shows the sum of
the row and column numbers (starting from 1).
Example (n=3):
234
345
456
Hint: Outer loop for rows, inner loop for columns.

🔹 3. Triangle Pattern
Ask the user for a number and print a right-angled triangle of numbers.
Example (input 5):
1
22
333
4444
55555
Hint: Nested loops — outer for lines, inner for repeating the number.

🔹 4. Character Matrix
Take a word from the user and print each character in a grid where each row
is the whole word.
Example (input Dog):
Dog
Dog
Dog
Hint: Outer loop runs as many times as the length of the word; inner loop
prints the word.

🔹 5. Multiplication Chart
Print a multiplication chart from 1 to 5 using nested loops (rows and
columns).
Example Output:
1x1=1 1x2=2 1x3=3 …
2x1=2 2x2=4 2x3=6 …

Hint: Nested loops make a table.

You might also like