Area of a triangle with two vertices at midpoints of opposite sides of a square and the other vertex lying on vertex of a square
Given a positive integer N representing the side of a square, the task is to find the area of a triangle formed by connecting the midpoints of two adjacent sides and vertex opposite to the two sides.
Examples:
Input: N = 10
Output: 37.5Input: N = 1
Output: 0.375
Approach: The given problem can be solved based on the following observations:
- The one side of the triangle will be the hypotenuse of the triangle formed with the vertices as two middle point and one vertex of the square at the intersection of the sides whose length of the side is given by
.
- The length of the other two sides of the triangle is given by
.
- Now, the sides of the triangle are known, therefore, the area of the triangle can be calculated using the Heron’s Formula.
Follow the steps below to solve the problem:
Below is the implementation of the above approach:
C++
|
37.5
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Original page link
Best Cool Tech Gadgets
Top favorite technology gadgets
0 comments:
Post a Comment