Basic Programming C# Examples

C# Program to Check If a triangle is Equilateral, Isosceles or Scalene

The Program in C# Program to Check If a triangle is Equilateral, Isosceles or Scalene is given below:

using System;

namespace TriangleTypeCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family,enter the first side length of the triangle: ");
            int a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter the second side length of the triangle: ");
            int b = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter the third side length of the triangle: ");
            int c = Convert.ToInt32(Console.ReadLine());

            if (a == b && b == c)
            {
                Console.WriteLine("Oay,this is an Equilateral Triangle.");
            }
            else if (a == b || b == c || a == c)
            {
                Console.WriteLine("Okay,this is an Isosceles Triangle.");
            }
            else
            {
                Console.WriteLine("Okay, this is a Scalene Triangle.");
            }
        }
    }
}

Output:

Hello Codeauri Family,enter the first side length of the triangle:
20
Enter the second side length of the triangle:
20
Enter the third side length of the triangle:
90
Okay,this is an Isosceles Triangle.

Pro-Tips💡

Here are the step by step execution of above program:

  1. Import the System namespace, which provides access to several commonly used classes and methods in C#.
  2. Define a namespace called TriangleTypeCheck to group related classes and objects.
  3. Define a class called Program within the namespace.
  4. Define the Main method within the Program class, which is the entry point of the program.
  5. In the Main method, the program prompts the user to input the lengths of the three sides of the triangle using Console.WriteLine and Console.ReadLine methods.
  6. The inputs are converted from string to integer using the Convert.ToInt32 method.
  7. An if...else statement is used to determine the type of triangle based on the values of a, b, and c. If all three sides are equal, the triangle is an equilateral triangle. If two sides are equal, the triangle is an isosceles triangle. If no sides are equal, the triangle is a scalene triangle.
  8. The type of triangle is printed to the console using Console.WriteLine.
  9. The Main method returns and the program terminates after displaying the triangle type.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X