Lab 0487979798
Lab 0487979798
Objective:
To understands and implement different types of loops in C++ (for, while, and do-while loops)
through hands-on coding exercises.
Instructions:
• No use of any AI-generative tools or online resources. You can use class notes/lectures
Write a C++ program where the user tries to guess a randomly generated number between 1 and
100 using a while loop. The program should give hints like "Too High" or "Too Low" until the user
guesses correctly.
Subtasks:
• Take a random number using std::rand() and store it into an integer variable (let’s say
comp_num). update the number as comp_num = comp_num %100 +1 .
• Repeatedly do this in a loop
o Take an integer as input from a user (store into variable guess) and compare it with the
comp_num.
o If the guess number is greater than the comp_num, output “Too High".
o If the guess number is less than the comp_num, output "Too Low",
o If the guess number is equal to the comp_num, output “the guess is correct”. This
resulted into exit from the loop
Example Output:
Task-2: Write a C++ program that prints the multiplication table up to 10 for all numbers from 2-20
(using nested loops).
Example Output:
2x1=2
2x2=4
.
.
2 x 10 = 20
3x 1 = 3
3x2=6
.
.
3 x 10 = 30
..
…
…
..
5x1=5
5 x 2 = 10
.
.
5 x 10 = 50
…
…
…
20x 1=20
20x2 =40
.
.
20 x10 =200