In this tutorial you will learn about the C Program to Check Triangle is Equilateral Isosceles or Scalene and its application with practical example.
C Program to Check Triangle is Equilateral Isosceles or Scalene
In this tutorial, we will learn to create a C program that will Check Triangle is Equilateral Isosceles or Scalene in C programming.
Prerequisites:-
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic Operations in C Programming.
- Conditional statements in C programming.
What is a scalene triangle?
A Scalene triangle is a triangle that has 3 unequal sides. Since all the three sides are unequal, this means all the three angles are also of different measures.
What is an equilateral triangle?
In geometry, a triangle is an equilateral triangle when it’s all the sides are equal. The triangle has three interior angles and the total of its interior angle is 180 degrees. Here all three angles are 60 Degrees.
Below is a figure for the equilateral triangle with all sides and the anglers are equal.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input three sides of the triangle. 3. Checking the conditions of triangles using the code. 4. Printing the type of the triangle. 5. End the program. |
Program Check Triangle is Equilateral Isosceles or Scalene:-
In this tutorial, we will create a program, that will Use sides to check Triangle is equilateral, isosceles, or scalene. First, we will take three sides from the input by the user. Then we will use the conditional statements to check which type of triangle is it. Then we will print the Triangle type.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/* C Program to Check Triangle is Equilateral Isosceles or Scalene */ #include<stdio.h>//Including the header files int main()//Body of the main function. { //declaring the variables for the program int s1, s2, s3; //s1 = it will store the first side of the triangle. //s2 = it will store the second side of the triangle. //s3 = it will store the third side of the triangle. //taking the input sides from the user. printf("\n Please Enter Three Sides of a Triangle : "); //scanning the input sides scanf("%d%d%d", &s1, &s2, &s3); //Checking the type of the triangle using conditional statement if(s1 == s2 && s2 == s3) { //Printing the type of the triangle. printf("\n This is an Equilateral Triangle"); } else if(s1 == s2 || s2 == s3 || s1 == s3) { //Printing the type of the triangle. printf("\n This is an Isosceles Triangle"); } else { //Printing the type of the triangle. printf("\n This is a Scalene Triangle"); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- s1 = it will hold the value for the input first side of the triangle.
- s2 = it will hold the value for the input second side of the triangle.
- s3 = it will hold the value for the input third side of the triangle.
Taking the Input of the three sides of the triangle.
Code to check the type of the triangle.
Printing the output for the triangle is valid or not.