C# program to find Area of Equilateral Triangle

Program

using System;
namespace AreaOfEquilateralTriangle
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the Length of Side:\t");
            float side = float.Parse(Console.ReadLine());
            float root = (float)Math.Sqrt(3) / 4;
            float area = root * side * side;
            Console.WriteLine("Area of Equilateral Triangle is:\t" + area);
       }
    }
}

This C# program calculates the area of an equilateral triangle using the side length provided by the user.

1. Namespace and Class Definition

  • The program is inside the AreaOfEquilateralTriangle namespace.
  • The Program class contains the Main() method where the logic is implemented.

2. Taking User Input

  • The program prompts the user to enter the length of a side.
  • The input is read as a string and converted into a float using float.Parse().

3. Calculating the Area

  • The formula for the area of an equilateral triangle is:
    [
    \text{Area} = \frac{\sqrt{3}}{4} \times \text{side}^2 ]
  • Math.Sqrt(3) / 4 is used to compute √3 / 4.
  • The formula is applied to calculate the area.

4. Displaying the Result

  • The computed area is printed using Console.WriteLine().

Key Points:

  • Uses Math.Sqrt(3) to compute √3 for accuracy.
  • Uses float data type to handle decimal values.
  • Prompts user for input dynamically and calculates the area.
  • Efficient and accurate formula implementation.

Output

Enter the Length of Side:       9
Area of Equilateral Triangle is:        35.07403