Area of circle which is inscribed in equilateral triangle
Last Updated :
27 Aug, 2022
Given here is an equilateral triangle with side length a, the task is to find the area of the circle inscribed in that equilateral triangle.
Examples:
Input : a = 4
Output : 4.1887902047863905
Input : a = 10
Output : 26.1799387799
Approach:
Area of equilateral triangle =
Semi perimeter of equilateral triangle = (a + a + a) / 2
Radius of inscribed circle r = Area of equilateral triangle / Semi perimeter of equilateral triangle
=
=
Area of circle = PI*(r*r) =
*** QuickLaTeX cannot compile formula:
*** Error message:
Error: Nothing to show, formula is empty
Below is the implementation of above approach:
C++
# include<bits/stdc++.h>
# define PI 3.14
using namespace std;
float circle_inscribed( int a)
{
return PI * (a * a) / 12;
}
int main()
{
int a = 4;
cout << circle_inscribed(a);
return 0;
}
|
Java
import java.io.*;
class GFG
{
static double PI = 3.14 ;
static double circle_inscribed( int a)
{
return PI * (a * a) / 12 ;
}
public static void main (String[] args)
{
int a = 4 ;
System.out.println(circle_inscribed(a));
}
}
|
Python3
from math import pi
def circle_inscribed(a):
return pi * (a * a) / 12
a = 4
print (circle_inscribed(a))
|
C#
using System;
class GFG
{
static double PI = 3.14;
static double circle_inscribed( int a)
{
return PI * (a * a) / 12;
}
public static void Main ()
{
int a = 4;
Console.WriteLine( circle_inscribed(a));
}
}
|
PHP
<?php
function circle_inscribed( $a )
{
return 3.14 * ( $a * $a ) / 12;
}
$a = 4;
echo circle_inscribed( $a );
|
Javascript
<script>
let PI = 3.14;
function circle_inscribed( a)
{
return PI * (a * a) / 12;
}
let a = 4;
document.write(circle_inscribed(a).toFixed(5));
</script>
|
Time complexity: O(1), since there is no loop or recursion.
Auxiliary Space: O(1), since no extra space has been taken.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...