Lab 7: Exercise: Total 100 Marks
Lab 7: Exercise: Total 100 Marks
Problem 1 [25]
You have used pow() function defined in cmath library. Your task is to implement similar functionality
i.e. input a number and its power from the user and then calculate the answer by using while loop. For
simplicity, suppose that number and power can take only integer values (both positive and negative).
Problem 2 [25]
Input a valid year from the user and output if it is leap year or not. A year that is exactly divisible by 4 is
a leap year, except for years that are divisible by 100, but these century years are leap years if they are
exactly divisible by 400.
For example, 2016 and 2000 were leap years but 1900 was not.
Problem 3 [25]
Consider a square grid of size NxN (input N from the user). Take another input from the user which will
indicate the cell number. You have to tell if that cell lies on the diagonal of the grid. For example, for a
grid of 5x5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
If the user enters 19, your program should output YES. For 14, NO. Remember that 5x5 is just an
example, grid can be of any size.
Problem 4 [25]
Input a number from the user and a position. Your program should output the digit at that position. If
position is more than the total digits, just print a statement informing the user that position does not
exist in the number or like this: