![]() |
VOOZH | about |
Given the P, B and H are the perpendicular, base and hypotenuse respectively of a right angled triangle. The task is to find the area of the incircle of radius r as shown below:
Examples:
Input: P = 3, B = 4, H = 5
Output: 3.14
Input: P = 5, B = 12, H = 13
Output: 12.56
Approach: Formula for calculating the inradius of a right angled triangle can be given as r = ( P + B - H ) / 2.
And we know that the area of a circle is PI * r2 where PI = 22 / 7 and r is the radius of the circle.
Hence the area of the incircle will be PI * ((P + B - H) / 2)2.
Below is the implementation of the above approach:
3.141593
Time Complexity : O(1)
Auxiliary Space: O(1)