Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle
Given the length of sides of an equilateral triangle, the task is to find the area and perimeter of Incircle of the given equilateral triangle. Examples:
Input: side = 6
Output: Area = 9.4. Perimeter = 10.88
Input: side = 9
Output: Area = 21.21, Perimeter = 16.32
Properties of an Incircle are:
- The center of the Incircle is same as the center of the triangle i.e. the point where the medians of the equilateral triangle intersect.
- Inscribed circle of an equilateral triangle is made through the midpoint of the edges of an equilateral triangle.
- The Inradius of an Incircle of an equilateral triangle can be calculated using the formula:
,
- where is the length of the side of equilateral triangle.
- Below image shows an equilateral triangle with incircle:
- Approach: Area of circle = and perimeter of circle = , where r is the radius of given circle. Also the radius of Incircle of an equilateral triangle = (side of the equilateral triangle)/ 3. Therefore,
- The formula used to calculate the area of Incircle using Inradius is:
- The formula used to calculate the perimeter of Incircle using Inradius is:
C
#include <math.h>
#include <stdio.h>
#define PI 3.14159265
float area_inscribed( float a)
{
return (a * a * (PI / 12));
}
float perm_inscribed( float a)
{
return (PI * (a / sqrt (3)));
}
int main()
{
float a = 6;
printf ( "Area of inscribed circle is :%f\n" ,
area_inscribed(a));
printf ( "Perimeter of inscribed circle is :%f" ,
perm_inscribed(a));
return 0;
}
|
Java
import java.lang.*;
class GFG {
static double PI = 3.14159265 ;
public static double area_inscribed( double a)
{
return (a * a * (PI / 12 ));
}
public static double perm_inscribed( double a)
{
return (PI * (a / Math.sqrt( 3 )));
}
public static void main(String[] args)
{
double a = 6.0 ;
System.out.println( "Area of inscribed circle is :"
+ area_inscribed(a));
System.out.println( "\nPerimeter of inscribed circle is :"
+ perm_inscribed(a));
}
}
|
Python3
import math
PI = 3.14159265
def area_inscribed(a):
return (a * a * (PI / 12 ))
def perm_inscribed(a):
return ( PI * (a / math.sqrt( 3 ) ) )
a = 6.0
print ( "Area of inscribed circle is :% f"
% area_inscribed(a))
print ( "\nPerimeter of inscribed circle is :% f"
% perm_inscribed(a))
|
C#
using System;
class GFG {
static double PI = 3.14159265;
public static double area_inscribed( double a)
{
return (a * a * (PI / 12));
}
public static double perm_inscribed( double a)
{
return (PI * (a / Math.Sqrt(3)));
}
public static void Main()
{
double a = 6.0;
Console.Write( "Area of inscribed circle is :"
+ area_inscribed(a));
Console.Write( "\nPerimeter of inscribed circle is :"
+ perm_inscribed(a));
}
}
|
PHP
<?php
$PI = 3.14159265;
function area_inscribed( $a )
{
global $PI ;
return ( $a * $a * ( $PI / 12));
}
function perm_inscribed( $a )
{
global $PI ;
return ( $PI * ( $a / sqrt(3) ) );
}
$a = 6;
echo ( "Area of inscribed circle is :" );
echo (area_inscribed( $a ));
echo ( "Perimeter of inscribed circle is :" );
echo (perm_inscribed( $a ));
?>
|
Javascript
Javascrip
let PI = 3.14159265
function area_inscribed(a)
{
return (a * a * (PI / 12))
}
function perm_inscribed(a)
{
return ( PI * (a / Math.sqrt(3) ) )
}
let a = 6.0
console.log( "Area of inscribed circle is :" , area_inscribed(a))
console.log( "\nPerimeter of inscribed circle is :" , perm_inscribed(a))
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
27 Aug, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...