Answer to Question #325625 in C# for Zarifa

Question #325625

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 a function to print the area and perimeter.(For C sharp)


1
Expert's answer
2022-04-08T01:49:57-0400
using System;

namespace triangle_class
{
    class Triangle
    {
            public int perimetr;
            public double area;
            public Triangle(int side_a, int side_b, int side_c)
            {
                int pp;    
                perimetr = side_a + side_b + side_c;
                pp = perimetr / 2;
                area = Math.Sqrt(pp*(pp-side_a)*(pp-side_b)*(pp-side_c));
           }
            public void print()
            {
                Console.WriteLine("Triangle:");
                Console.WriteLine("Area = {0}", area);
                Console.WriteLine("Perimetr = {0}", perimetr);
            }
    }
    
    class Program
    {
        public static void Main(string[] args)
        {
            Triangle triangle = new Triangle(3, 4, 5);
            
            triangle.print();
            
            Console.Write("\nPress any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

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