Lab No.
5
While loop
Task No.1
Repeatedly print the value of the variable XYZ, decreasing it by 0.5 each time, as long as XYZ remains
positive.
Task No.2
Print the square roots of the first 50 odd positive integers.
Task No.3
Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.-
4! = 1*2*3*4 = 24
3! = 3*2*1 = 6
2! = 2*1 = 2
Also,
1! = 1
0! = 0
Write a C++ program to calculate factorial of a number given by user.
Task No.4
Use while loop to print the following patterns.
a.
*
**
***
****
*****
******
*******
********
b.
*
**
****
******
****
**
*
c.
1010101
10101
101
1
Task No.5
Take 15 integers values from user using while loop. Ask the user to decide by taking input from user that
what he wants to perform. Show the following menu to the user
Enter 1 for sum
Enter 2 for average
Enter 3 to find the largest number
Display the results accordingly
Task No.6
Take integer inputs from user until he/she presses q ( Ask to press q to quit after every integer input ).
Print average and product of all numbers.
Task No.8
Drive the user crazy by insisting they re-enter a particular input no matter what they enter. Be creative...