Program to calculate area and perimeter of equilateral triangle

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.

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to find area
// and perimeter of equilateral triangle
#include <bits/stdc++.h>
using namespace std;
  
// Function to calculate Area 
// of equilateral triangle
float area_equi_triangle(float side)
{
    return sqrt(3) / 4 * side * side;
}
  
// Function to calculate Perimeter 
// of equilateral triangle
float peri_equi_triangle(float side)
{
    return 3 * side;
}
  
// Driver Code
int 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;
}
chevron_right

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program to find area and
// perimeter of equilateral triangle
import 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.
chevron_right

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to calculate Area and 
# Perimeter of equilateral Triangle
  
# Importing Math library for sqrt
from math import *
  
# Function to calculate Area 
# of equilateral triangle
def area_equilateral( side ):
    area = (sqrt(3) / 4) * side * side
    print ("Area of Equilateral Triangle: % f"% area)
  
# Function to calculate Perimeter
# of equilateral triangle 
def perimeter( side ):
    perimeter = 3 * side
    print ("Perimeter of Equilateral Triangle: % f"% perimeter)
      
# Driver code
side = 4
area_equilateral( side )
perimeter( side )
chevron_right

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# Program to find area and
// perimeter of equilateral triangle
using 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.
chevron_right

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to find area
// and perimeter of equilateral triangle
  
  
// Function to calculate Area 
// of equilateral  triangle
function area_equi_triangle( $side)
{
    return sqrt(3) / 4 * $side * $side;
}
  
// Function to calculate Perimeter 
// of equilateral  triangle
function 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.
?>
chevron_right


Output :
Area of Equilateral Triangle: 6.9282
Perimeter of Equilateral Triangle: 12

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.





Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : vt_m, nidhi_biet

Article Tags :
Practice Tags :