📜  计算等边三角形面积和周长的程序

📅  最后修改于: 2021-05-04 09:17:57             🧑  作者: Mango

等边三角形是三个边和角度都相等的三角形。等边三角形的所有三个内角均为60度。

    等边三角形的面积:
  • 如果我们知道等边三角形各边的长度,则可以使用下面提到的公式来计算等边三角形的面积。
    Area of Equilateral Triangle = (sqrt(3)/4) * a * a    
  • 如果我们知道等边三角形的高度长度以及边的长度,那么我们可以使用下面提到的公式来计算其面积。
    Area of Equilateral Triangle = (1/2) x Side x Altitude

    等边三角形的周长:

    Perimeter of Equilateral Triangle :  3 X a

    面积公式如何工作?
    让我们看下图。我们知道一个三角形是1/2 *基数*高度。 h的值是sqrt(a 2 –(a / 2) 2 )= sqrt(3)* a /2。因此,面积变为1/2 * a *(sqrt(3)* a / 2)=(sqrt (3)/ 4)* a * a

    例子 :

    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++
    // CPP program to find area
    // and perimeter of equilateral triangle
    #include 
    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;
    }


    Java
    // 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.


    Python
    # 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 )


    C#
    // 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.


    PHP


    输出 :

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