Problem of the day
Programming languages have some conditional / decision-making statements that execute when some specific condition is fulfilled.
Switch-case is one of the ways to implement them.
Choice 1 is to find the area of a circle having radius 'r'.
Choice 2 is to find the area of a rectangle having dimensions 'l' and 'b'.
You are given the choice 'ch' and an array 'a'.
If ‘ch’ is 1, ‘a’ contains a single number ‘r’. If ‘ch’ is 2, ‘a’ contains 2 numbers, ‘l’ and ‘b’.
Consider the choice and print the appropriate area.
Input: ‘ch’ = 2 and ‘a’ = [3, 2]
Output: area = 6
Explanation: Since the choice ‘ch’ is 2, we have to print the area of the rectangle having ‘l’ = 3 and ‘b’ = 2, which is 6.
The first line contains an integer ‘ch’, the choice.
If ‘ch’ is 1, the second line contains 1 number ‘r’, the radius of the circle.
If ‘ch’ is 2, the second line contains 2 numbers, ‘l’ and ‘b’, the dimensions of the rectangle.
The only line of the output contains a floating point number representing the area of the shape.
You do not need to print anything; it has already been taken care of. Just return the area calculated. It will be rounded off to 5 decimal places and printed.
2
3 2
6.00000
Since the choice ‘ch’ is 2, we have to print the area of the rectangle having ‘l’ = 3 and ‘b’ = 2, which is 6.
1
3
28.27433
Since the choice ‘ch’ is 1, we have to print the area of the circle having ‘r’ = 3, which is approximately 28.274333882308138. Rounded off to 5 decimal places, we get 28.27433.
The expected time complexity is O(1).
1 <= ‘ch’ <= 2
1 <= ‘r’ <= 100
1 <= ‘l’, ‘b’ <= 100
Time limit: 1 second