C#: Check whether a triangle is Equilateral, Isosceles or Scalene
Write a C# Sharp program to check whether a triangle is Equilateral, Isosceles or Scalene.
Sample Solution:-
C# Sharp Code:
using System; // Importing the System namespace
public class Exercise14 // Declaration of the Exercise14 class
{
public static void Main() // Entry point of the program
{
int sidea, sideb, sidec; // Declaration of variables to store triangle sides
Console.Write("\n\n"); // Printing new lines
Console.Write("Check whether a triangle is Equilateral, Isosceles or Scalene:\n"); // Displaying the purpose of the program
Console.Write("----------------------------------------------------------------"); // Displaying a separator
Console.Write("\n\n");
// Prompting user to input the three sides of a triangle
Console.Write("Input side 1 of triangle: ");
sidea = Convert.ToInt32(Console.ReadLine());
Console.Write("Input side 2 of triangle: ");
sideb = Convert.ToInt32(Console.ReadLine());
Console.Write("Input side 3 of triangle: ");
sidec = Convert.ToInt32(Console.ReadLine());
// Checking conditions to determine the type of triangle based on side lengths
if (sidea == sideb && sideb == sidec)
{
Console.Write("This is an equilateral triangle.\n"); // Printing a message for an equilateral triangle
}
else if (sidea == sideb || sidea == sidec || sideb == sidec)
{
Console.Write("This is an isosceles triangle.\n"); // Printing a message for an isosceles triangle
}
else
{
Console.Write("This is a scalene triangle.\n"); // Printing a message for a scalene triangle
}
}
}
Sample Output:
Check whether a triangle is Equilateral, Isosceles or Scalene: ---------------------------------------------------------------- Input side 1 of triangle: 40 Input side 2 of triangle: 20 Input side 3 of triangle: 20 This is an isosceles triangle.
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C# Sharp program to read temperature in centigrade and display suitable message according to temperature.
Next: Write a C# Sharp program to check whether a triangle can be formed by the given value for the angles.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics