C# Chapters

C# Program to Calculate the Area of a Triangle

Operators - C# Language Fundamentals
using System;

public class Program
{
    public static void Main()
    {
        int A, B, C, S, Area;
        
        Console.Write("Enter Length of Triangle's three sides : ");
        A = Convert.ToInt32(Console.ReadLine());
        B = Convert.ToInt32(Console.ReadLine());
        C = Convert.ToInt32(Console.ReadLine());
        
        S = (A + B + C) / 2;
        Area = (int) Math.Sqrt(S * (S - A) * (S - B) * (S - C));
        
        Console.Write("\nArea of Triangle is : " + Area);
    }
}

Output :
Enter Length of Triangle's three sides : 10
20
20

Area of Triangle is : 96

Description :

Area of Trangle can be calculated as
s x (s-a) x (s-b) x (s-c)

Where s = half the perimeter (a+b+c)/2


Leave a comment
Recent Comments
No Comments