C# Function that prints perimeter and area of right triangle.

/* C# Function that prints perimeter and area of right triangle. */
using System;
public class Demo
{
    public static float triangle_area(float a, float b, float c)
    {
        float s, area;
        s = (a + b + c) / 2;
        area = (float)(Math.Sqrt(s * (s - a) * (s - b) * (s - c)));
        return area;
    }
    public static float triangle_perimeter(float a, float b, float c)
    {
        float area, perimeter;
        perimeter = a + b + c;
        return perimeter;
    }

    public static void Main(string[] args)
    {
        float a, b, c, peri, ar;
        Console.WriteLine("\nPlease Enter three sides of triangle");
        a = float.Parse(Console.ReadLine());
        b = float.Parse(Console.ReadLine());
        c = float.Parse(Console.ReadLine());
        peri = triangle_perimeter(a, b, c);
        ar = triangle_area(a, b, c);
        Console.WriteLine("\nPerimeter of Traiangle = {0}\n", peri);
        Console.WriteLine("\nArea of triangle = {0}\n", ar);
        Console.ReadLine();
    }
}

Output :
Please Enter three sides of triangle
2
3
4

Perimeter of Traiangle = 9.00

Area of triangle = 2.90



Leave a comment