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)
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);
}
}
}
Comments
Leave a comment