The sum of the lengths of any two sides of a triangle is greater than the length of the third side.
In the figure, the following inequalities hold. a + b > c a + c > b b + c > a
Example 1: Check whether it is possible to have a triangle with the given side lengths. 7 , 9 , 13 Add any two sides and see if it is greater than the other side. The sum of 7 and 9 is 16 and 16 is greater than 13 . The sum of 9 and 13 is 21 and 21 is greater than 7 . The sum of 7 and 13 is 20 and 20 is greater than 9 . This set of side lengths satisfies the Triangle Inequality Theorem. These lengths do form a triangle.
Example 2: Check whether the given side lengths form a triangle. 4 , 8 , 15 Check whether the sides satisfy the Triangle Inequality Theorem. Add any two sides and see if it is greater than the other side. The sum of 4 and 8 is 12 and 12 is less than 15 . This set of side lengths does not satisfy Triangle Inequality Theorem. These lengths do not form a triangle. Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene. Equilateral triangle: An equilateral triangle is a triangle in which all three sides are equal. In the familiar Euclidean geometry, equilateral triangles are also equiangular; that is, all three internal angles are also congruent to each other and are each 60°. Isosceles triangle: An isosceles triangle is a triangle that has two sides of equal length. Scalene triangle: A scalene triangle is a triangle that has three unequal sides, such as those illustrated above. Pictorial Presentation: Sample Solution: C Code: Sample Output: Flowchart: C Programming Code Editor: Improve this sample solution and post your code through Disqus. Previous: Write a C program to read temperature in centigrade and display a suitable message according to temperature state below.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Variable declaration placement in C: It compiles successfully because GCC allows the declaration of s as a GNU extension, even though it's not part of the C89 or ANSI standard. If you want to adhere strictly to those standards, you must pass the -pedantic flag. The declaration of c at the start of a { } block is part of the C89 standard; the block doesn't have to be a function. Ref : https://bit.ly/3luxCG7 A polygon having three sides is said to be a triangle if each and every side is smaller than the sum of other two sides. Based on sides, A triangle can be classified into three categories scalene, equilateral and isosceles triangle. An isosceles triangle is a triangle in which its two sides are equal. An equilateral triangle is a triangle in which all three sides are equal. A scalene triangle is a triangle in which no sides are equivalent to one other. We are supposing interval [1,10] for test cases and will generate test cases using Boundary value analysis accordingly. Expected Output can be [ Scalene Triangle, Not a Triangle, Equilateral triangle, Isosceles Triangle ] Program: #include<conio.h> #include<stdio.h> void main() { int a,b,c,result; printf(" Enter the values of a, b and c : = "); scanf("%d %d %d", &a,&b,&c); if(((a+b)>c)&&((b+c)>a)&&((c+a)>b)) { 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"); } else printf("\n not a triangle"); getch(); }In Boundary Value Analysis, 4N+1 test case will be generated, which means, in this case, 4*3+1 = 13 test cases.
Testing Result of the ProgramNot a Triangle Equilateral triangle Isosceles Triangle |