Answer to Question #325626 in C# for Zarifa

Question #325626

Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5 units by creating a class named 'Triangle' with the constructor having the three sides as its parameters.(For C sharp)

1
Expert's answer
2022-04-08T17:54:38-0400
 internal class Program
    {
        class Triangle
        {
            public double AB { get; set; }
            public double BC { get; set; }
            public double CA { get; set; }
            public Triangle(double ab, double bc, double ca)
            {
                AB = ab;
                BC = bc;
                CA = ca;
            }


            public string Perimeter()
            {
                return $"P = {AB}+{BC}+{CA} = {AB+BC+CA}";
            }
            public string Area()
            {
                double p = (AB + BC + CA) / 2;
                return $"S = {Math.Sqrt(p * (p - AB) * (p - BC) * (p - CA))}";
            }
        }
        static void Main()
        {
            Triangle triangle = new Triangle(3, 4, 5);
            Console.WriteLine(triangle.Perimeter());
            Console.WriteLine(triangle.Area());
            Console.ReadKey();
        }
     
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS