Horje
Area of a circle inscribed in a rectangle which is inscribed in a semicircle

Given a semicircle with radius R, which inscribes a rectangle of length L and breadth B, which in turn inscribes a circle of radius r. The task is to find the area of the circle with radius r.
Examples: 
 

Input : R = 2
Output : 1.57

Input : R = 5
Output : 9.8125

 

 

Approach:
 

We know the biggest rectangle that can be inscribed within the semicircle has, length, l=?2R/2
breadth, b=R/?2(Please refer
Also, the biggest circle that can be inscribed within the rectangle has radius, r=b/2=R/2?2(Please refer
So area of the circle, A=?*r^2=?(R/2?2)^2 
 

 

C++

<?php
// PHP Program to find the area
// of the circle inscribed within
// the rectangle which in turn
// is inscribed in a semicircle
 
// Function to find the area
// of the circle
function area($r)
{
    // radius cannot be negative
    if ($r < 0)
        return -1;
 
    // area of the circle
    $area = 3.14 * pow($r /
              (2 * sqrt(2)), 2);
    return $area;
}
 
// Driver code
$a = 5;
echo area($a);
 
// This code is contributed by mits

Javascript

<script>
// javascript Program to find the area of the circle
// inscribed within the rectangle which in turn
// is inscribed in a semicircle
 
// Function to find the area of the circle
function area(r)
{
 
    // radius cannot be negative
    if (r < 0)
        return -1;
 
    // area of the circle
    var area = (3.14 * Math.pow(r / (2 * Math.sqrt(2)), 2));
    return area;
}
 
// Driver code
var a = 5;
document.write( area(a).toFixed(6));
 
// This code contributed by shikhasingrajput
 
</script>

Output: 

9.8125

 

Time Complexity: O(1)

Auxiliary Space: O(1)




Reffered: https://www.geeksforgeeks.org


C++ Programs

Related
Area of a square inscribed in a circle which is inscribed in a hexagon Area of a square inscribed in a circle which is inscribed in a hexagon
Count Numbers with N digits which consists of odd number of 0&#039;s Count Numbers with N digits which consists of odd number of 0&#039;s
Program for n-th even number Program for n-th even number
Program to find the Radius of the incircle of the triangle Program to find the Radius of the incircle of the triangle
C++ Program to Make a Simple Calculator C++ Program to Make a Simple Calculator

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
9