Lab 9 (Loops)
Lab 9 (Loops)
Lab 09
Topic Loop Statement
Objective Learning how to use repetition statements
do while:
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.
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
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
(a) (b)
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
Task 12
(b)
(a)
*******
*******
******
******
*****
*****
****
****
***
***
**
**
*
*
Task 13
(a)
(b)
1
12345
12
1234
123
123
1234
12
12345
1
Task 14
54321
4321
321
21
Task 15
24
369
4 8 12 16
5 10 15 20 25
Task 16
(a) (b)
1 7777777
22 666666
333 55555
4444 4444
55555 333
666666 22
7777777 1