The program determines the type of triangle based on the input provided by a user.
A triangle can be broadly classified according to the length of its sides and the angle between the sides.
Based on the sides, there are three types of triangle
1. Equilateral Triangle
2. Isosceles Triangle
3. Scalene Triangle
Based on the angles, there are also 3 types:
1. Acute triangle
2. Right triangle
3. Obtuse triangle
In this article, we’ll be discussing triangles that are classified based on sides, and implementing the same in the program.
The program also implies Triangle Inequality Theorem to validate whether the given sides can be a triangle or not.
Program:
#include<conio.h> #include<stdio.h> #include<math.h> void main () { int a, b, c, flag = -1; printf (" Enter the values of a, b and c : = "); scanf ("%d %d %d", &a, &b, &c); if ((a >= 0 && a <= 10) && (b >= 0 && b <= 10) && (c >= 0 && c <= 10)){ // Triangle Inequality Theorem : every side's length should be shorter than sum of other two side if (((a + b) > c) && ((b + c) > a) && ((c + a) > b)){ flag = 1; if ((a == b) && (b == c)) printf ("\n It is an Equilatral Triangle"); else if ((a == b) || (b == c) || (c == a)) printf ("\n It is an isosceles Triangle"); else printf ("\n It is a Scalene Triangle"); } } if (flag == -1) printf ("Given side inputs, can't be a triangle "); getch (); }
Not a Triangle
Enter the values of a, b and c : = 11 5 5 Given side inputs, can't be a triangle
Equilateral triangle
Enter the values of a, b and c : = 4 4 4 It is an Equilateral Triangle
Isosceles Triangle
Enter the values of a, b and c : = 2 3 2 It is an isosceles Triangle
This post was last modified on August 26, 2022