Array ( [0] => [1] => questions [2] => Strings [3] => Area-of-Polygon )
Given a list of integers denoting number of sizes of polygons. You have to find the area of given polygon. Note: Program need to be driven from the main program. As per the polygon type area need to be calculated. Menu need to be displayed after every calculation. Format of Menu: Please select from the menu: 1. Triangle 2. Square 3. Rectangle 4. Rhombus 5. Pentagon 6. Circle 7. exit
First line contains a number N. Next line contains N integers separated by spaces.
Print the area of given polygon.
3 3 4 5
6
4 1 2 1 2
2
3 12 16 20
96
Login to see Discussion
Here approach for all the polygons is same only formula changes as per the polygon
Step-i) In a infinite loop ask user to for which polygon he/she wants are
Step-ii) Take the required inputs
Step-iii) call the particular method
Step-iv) calculate are using formula
Step-v) return the value
Step-vi) repeat ii, iii,iv and v steps still user exits
Time Complexity: O(1)
Space Complexity: O(1)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution