Program to calculate area and perimeter of equilateral triangle

22 Jun, 2022
An equilateral triangle is a triangle in which all three sides and angles are equal. All three internal angles of equilateral triangle measures 60 degree.
If we know the length of each sides of equilateral triangle, then we can use below mentioned formula to calculate area of equilateral triangle.
Area of Equilateral Triangle = (sqrt(3)/4) * a * a    
If we know the length of altitude of equilateral triangle along with the length of side, then we can use below mentioned formula to calculate it’s area.
Area of Equilateral Triangle = (1/2) x Side x Altitude
Perimeter of Equilateral Triangle :
Perimeter of Equilateral Triangle :  3 X a
How does the area formula work?Let us take a look at below diagram. We know are of a triangle is 1/2 * base * height. The value of h is sqrt(a2 – (a/2)2) = sqrt(3) * a / 2. So the area becomes 1/2 * a * (sqrt(3) * a / 2) = (sqrt(3)/4) * a * a
 
Examples:
Input : side = 4
Output : Area of Equilateral Triangle: 6.9282
        Perimeter of Equilateral Triangle: 12
Input : side = 12
Output : Area of Equilateral Triangle: 62.3538
        Perimeter of Equilateral Triangle: 36
C++
Java
Python
C#
PHP
Javascript
// CPP program to find area// and perimeter of equilateral triangle#include <bits/stdc++.h>using namespace std; // Function to calculate Area// of equilateral trianglefloat area_equi_triangle(float side){    return sqrt(3) / 4 * side * side;} // Function to calculate Perimeter// of equilateral trianglefloat peri_equi_triangle(float side){    return 3 * side;} // Driver Codeint main(){    float side = 4;    cout << "Area of Equilateral Triangle: "        << area_equi_triangle(side) << endl;    cout << "Perimeter of Equilateral Triangle: "        << peri_equi_triangle(side);    return 0;}
// Java Program to find area and// perimeter of equilateral triangleimport java.io.*; class GFG{    // Function to calculate    // Area of equilateral triangle    static float area_equi_triangle(float side)    {         return (float)(((Math.sqrt(3)) / 4) *                        side * side);    }     // Function to calculate    // Perimeter of equilateral    // triangle    static float peri_equi_triangle(float side)    {        return 3 * side;    }         // Driver Code    public static void main(String arg[])    {        float side = 4;        System.out.print("Area of Equilateral Triangle:");        System.out.println(area_equi_triangle(side));        System.out.print("Perimeter of Equilateral Triangle:");        System.out.println(peri_equi_triangle(side));    }} // This code is contributed// by Anant Agarwal.
# Python3 program to calculate Area and# Perimeter of equilateral Triangle # Importing Math library for sqrtfrom math import * # Function to calculate Area# of equilateral triangledef area_equilateral( side ):    area = (sqrt(3) / 4) * side * side    print ("Area of Equilateral Triangle: % f"% area) # Function to calculate Perimeter# of equilateral triangledef perimeter( side ):    perimeter = 3 * side    print ("Perimeter of Equilateral Triangle: % f"% perimeter)     # Driver codeside = 4area_equilateral( side )perimeter( side )
// C# Program to find area and// perimeter of equilateral triangleusing System; class GFG{    // Function to calculate    // Area of equilateral triangle    static float area_equi_triangle(float side)    {         return (float)(((Math.Sqrt(3)) / 4) *                        side * side);    }     // Function to calculate    // Perimeter of equilateral    // triangle    static float peri_equi_triangle(float side)    {        return 3 * side;    }         // Driver Code    public static void Main()    {        float side = 4;        Console.Write("Area of Equilateral Triangle:");        Console.WriteLine(area_equi_triangle(side));        Console.Write("Perimeter of Equilateral Triangle:");        Console.WriteLine(peri_equi_triangle(side));    }} // This code is contributed// by vt_m.
<?php// PHP program to find area// and perimeter of equilateral triangle  // Function to calculate Area// of equilateral trianglefunction area_equi_triangle( $side){    return sqrt(3) / 4 * $side * $side;} // Function to calculate Perimeter// of equilateral trianglefunction peri_equi_triangle( $side){    return 3 * $side;} // Driver Code $side = 4;echo("Area of Equilateral Triangle: ");echo(area_equi_triangle($side));echo("\n");echo("Perimeter of Equilateral Triangle: ");echo( peri_equi_triangle($side)); // This code is contributed// by vt_m.?>
<script>    //Javascript program to find area    // and perimeter of equilateral triangle         // Function to calculate    // Area of equilateral triangle    function area_equi_triangle(side)    {        return (((Math.sqrt(3)) / 4) * side * side).toFixed(4);    }         // Function to calculate    // Perimeter of equilateral    // triangle    function peri_equi_triangle(side)    {        return 3 * side;    }         //Driver code    var side = 4;    document.write("Area of Equilateral Triangle:");    document.write(area_equi_triangle(side)+"\n");    document.write("Perimeter of Equilateral Triangle:");    document.write(peri_equi_triangle(side)+"\n");         //This code is contributed by shruti456rawal</script>
Area of Equilateral Triangle: 6.9282
Perimeter of Equilateral Triangle: 12
Time Complexity: O(1) 
Auxiliary Space: O(1)
vt_m
nidhi_biet
shruti456rawal
mailaruyashaswi
area-volume-programs
Geometric
School Programming
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program for distance between two points on earth
Find if two rectangles overlap
Check whether triangle is valid or not if sides are given
Line Clipping | Set 1 (Cohen–Sutherland Algorithm)
Window to Viewport Transformation in Computer Graphics with Implementation
Python Dictionary
Reverse a string in Java
Arrays in C/C++
Introduction To PYTHON
Object Oriented Programming in C++