Array ( [0] => [1] => questions [2] => Popular-Algorithms [3] => Area-of-Polygon ) Arrays | Area of Polygon | THE INQUISITIVE





Area of Polygon

LEVEL:Beginner

Description

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

Input Format

First line contains a number N. Next line contains N integers separated by spaces.

Output Format

Print the area of given polygon.


Example 1:

Input
3
3 4 5
Output
6
Example 2:

Input
4
1 2 1 2				
Output
2
Example 3:

Input
3
12 16 20
Output
96

oops

Login to see Discussion




Approach

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.

oops

Login to see Solution