Area of largest Circle that can be inscribed in a SemiCircle
Last Updated :
21 Jun, 2022
Given a semicircle with radius R, the task is to find the area of the largest circle that can be inscribed in the semicircle.
Examples:
Input: R = 2
Output: 3.14
Input: R = 8
Output: 50.24
Approach: Let R be the radius of the semicircle
- For Largest circle that can be inscribed in this semicircle, the diameter of the circle must be equal to the radius of the semi-circle.
- So, if the radius of the semi-circle is R, then the diameter of the largest inscribed circle will be R.
- Hence the radius of the inscribed circle must be R/2
- Therefore the area of the largest circle will be
Area of circle = pi*Radius2
= pi*(R/2)2
since the radius of largest circle is R/2
where R is the radius of the semicircle
-
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float circlearea( float R)
{
if (R < 0)
return -1;
float a = 3.14 * R * R / 4;
return a;
}
int main()
{
float R = 2;
cout << circlearea(R) << endl;
return 0;
}
|
Java
class GFG
{
static float circlearea( float R)
{
if (R < 0 )
return - 1 ;
float a = ( float )(( 3.14 * R * R) / 4 );
return a;
}
public static void main (String[] args)
{
float R = 2 ;
System.out.println(circlearea(R));
}
}
|
Python3
def circlearea(R) :
if (R < 0 ) :
return - 1 ;
a = ( 3.14 * R * R) / 4 ;
return a;
if __name__ = = "__main__" :
R = 2 ;
print (circlearea(R)) ;
|
C#
using System;
class GFG
{
static float circlearea( float R)
{
if (R < 0)
return -1;
float a = ( float )((3.14 * R * R) / 4);
return a;
}
public static void Main ( string [] args)
{
float R = 2;
Console.WriteLine(circlearea(R));
}
}
|
Javascript
<script>
function circlearea(R)
{
if (R < 0)
return -1;
var a = 3.14 * R * R / 4;
return a;
}
var R = 2;
document.write(circlearea(R));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...