Lab-05
Lab-05
Lab - 05
Iterative Algorithms,
Support for Iterative Algorithms
through C/C++ Loops,
Real-World Applications
[Azad’s Law: The one facilitating cheating will be punished with 0 marks]
If you want to do something repetitively, you can do it effectively using loops. Consider
an example where one has to write a program to print 1,2,3, …..,N integers where N is
the input taken from the user.
TASK - 01 : Take the positive integer N from the user and print the following series:
TASK - 02 : Write a program to figure out whether N is a prime number or not. N will be
taken as input from the user.
TASK - 03 : Take the number of cities of Pakistan as input from the user. Ask the user to
enter the population of each city. Find out the mean, maximum and minimum
population?
TASK - 04: Imagine you are playing a grid (4x4) game where the player can move in
four directions Up, Down, Right and Left. Take the initial position of the player from the
user e.g. (1,2). Now take the direction in which the player will move and keep doing it
until it collides with the boundary. Figure out whether it collides with the boundary or
not? If it collides, it should simply exit by printing the coordinate of the boundary in the
form “The player has reached the boundary at (x,y)” where x,y will be the coordinates of
the boundary.
(1,1) (4,1)
(1,4) (4,4)
TASK - 06: Cricket Statistics - There is cricket fever out there everywhere in Pakistan.
Consider Babar Azam statistics for the last few world cups. Take the number of matches
he has played in world cups. Now take the runs scored by Babar Azam in each match
along with the balls he faced. At the end your program should print the following for
Babar Azam:
● strike rate,
● batting average
● minimum score
● maximum score
● number of centuries
Good Luck