logo image

C# program to calculate triangle circumference

57


Following program shows you how to calculate triangle circumference. This program gets triangle sides from user and calculates circumference and prints it using following formula Circumference = side1 + side2 + side3

using System;

class MainClass {
  public static void Main (string[] args) {
    Console.WriteLine("Enter the side1 of triangle:");
    double triangleSide1 = Convert.ToDouble(Console.ReadLine());
    Console.WriteLine("Enter the side2 of triangle:");
    double triangleSide2 = Convert.ToDouble(Console.ReadLine());
    Console.WriteLine("Enter the side3 of triangle:");
    double triangleSide3 = Convert.ToDouble(Console.ReadLine());
    double circumferenceOfTriangle = triangleSide1 + triangleSide2 + triangleSide3;
    Console.WriteLine("Circumference of triangle is: " + circumferenceOfTriangle);

  }
}

Output:

Enter the side1 of triangle:
 12
Enter the side2 of triangle:
 15
Enter the side3 of triangle:
 18
Circumference of triangle is: 45