0% found this document useful (0 votes)
35 views7 pages

Lab 9 Nested Loops

Uploaded by

Maaz Nasir
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)
35 views7 pages

Lab 9 Nested Loops

Uploaded by

Maaz Nasir
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
You are on page 1/ 7

Introduction to Computing

Lab 09
Topic Loop Statement
Objective Learning how to use repetition statements

do while:

The general form of do while loop is:

Flow of do while loop:

The statement executes first, and then the expression is evaluated. If the expression evaluates to true,
the statement executes again. As long as the expression in a do. . .while statement is true, the statement
executes. To avoid an infinite loop, you must, once again, make sure that the loop body contains a
statement that ultimately makes the expression false and assures that it exits properly. In C++, do is a
reserved word.

Nested Repetition statement:

A repetition statement is defined inside a repetition statement is called nested repetition.


Task 1
Write a C++ program to print a hollow triangle on console using Loop statement as shown below:

OUTPUT:

Task 2
Write a C++ program to print a filled triangle on console using loop statement as shown below:

OUTPUT:

Task 3
Write a C++ program to print a hollow hexagonal shape on console using loop statement as shown
below:

OUTPUT:
Task 4
Write a C++ program to print a filled hexagonal shape on console using

loop statement as shown below:

OUTPUT:

Task 5
Write a C++ program to print a hollow square shape on console using loop statement as shown
below:

OUTPUT:

Task 6
Write a C++ program to print a filled square shape on console using loop statement as shown
below:

OUPUT:
Task 7
Write a C++ program to print a hollow diamond shape on console using loop statement as shown
below:

OUTPUT:

Task 8
Write a C++ program to print a filled diamond shape on console using loop statement as shown
below:

OUTPUT:

Task 9
Print Square in the middle of console screen as follows using loop statement as shown below:

OUTPUT:
Task 10
Print Square in the middle of console screen as follows using loop statement as shown below:

OUTPUT:

Task 11

Write a program to print the following shape on the screen

(a) (b)
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******

Task 12

Write a program to print the following shape on the screen.

(b)
(a)
*******
*******
******
******
*****
*****
****
****
***
***
**
**
*
*
Task 13

Write a program to print the following shape on the screen

(a)
(b)
1
12345
12
1234
123
123
1234
12
12345
1

Task 14

Write a program to print the following shape on the screen.

54321

4321

321

21

Task 15

Write a program to print the following shape on the screen

24

369

4 8 12 16

5 10 15 20 25
Task 16

Write a program to print the following shape on the screen

(a) (b)
1 7777777
22 666666
333 55555
4444 4444
55555 333
666666 22
7777777 1

You might also like