Wednesday 8 August 2018

Pool

QUESTION DESCRIPTION :

You are planning to go for swimming classes. You would prefer to enroll in the centre which has the swimming pool of a greater area. In the first center that you visit, the swimming pool is circular shape (radius- r). In the next center you visit, the swimming pool is of square shape (size-S). Write a program that will help you to make the choice of the swimming pool.

Input Format: Input consists of 2 integers. The first one corresponds to the Radius of the circle, and the second one is the Side of the square

TEST CASE 1

INPUT
 
20
5

OUTPUT

I prefer centre 1


TEST CASE 2

INPUT

5
20

OUTPUT

I prefer centre 2


EXPLANATION :

The question requires you to input the radius of a circle, side of a square and then compare their areas, the one with the bigger area is the choice of the person. 

ALGORITHM :

Although this code is very easy we can add a space optimization by directly using the result of the calculation.

Steps:
  1. Input the Radius(R) and Side(S) of the circle and square respectively.
  2. Calculate the area of Circle (π*r*r) > Area1
  3. Calculate the area of the square (s*s) > Area2
  4. Compare the areas:
    1. If Area1< Area2 print "I prefer centre 2"
    2. If Area1> Area2 print "I prefer centre 1"
  5. Exit
P.S. Optimizations such as using less variables are mostly not relevant in the 21st Century scenario as the RAM add HDD sizes are large but such optimizations are recommended wherever possible in order to become a better programmer.

SOLUTION : (Please use this as reference only)



Link to Code : Pool

(Please Try To Refrain From Copying The Code)

No comments:

Post a Comment