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 with easy code)
using System;
namespace MathApp
{
class Program
{
public class Triangle
{
public int A { get; set; }
public int B { get; set; }
public int C { get; set; }
public Triangle (int a, int b, int c)
{
A = a;
B = b;
C = c;
}
public void Square ()
{
double p = (A + B + C) / 2;
Console.WriteLine($"A = {A}, B = {B}, C = {C}, S = {Math.Sqrt(p*(p-A)*(p-B)*(p-C))}");
}
}
static void Main()
{
Triangle FirstTriangle = new (3,4,5);
FirstTriangle.Square();
}
}
}
Comments
Leave a comment