How many scenario will you write to check whether its an equilateral triangle or not ?( triangle with equal sides?

The sum of the lengths of any two sides of a triangle is greater than the length of the third side.

How many scenario will you write to check whether its an equilateral triangle or not ?( triangle with equal sides?

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.

Last update on August 19 2022 21:51:29 (UTC/GMT +8 hours)

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:

How many scenario will you write to check whether its an equilateral triangle or not ?( triangle with equal sides?

Sample Solution:

C Code:

#include <stdio.h> int main() { int sidea, sideb, sidec; //are three sides of a triangle /* * Reads all sides of a triangle */ printf("Input three sides of triangle: "); scanf("%d %d %d", &sidea, &sideb, &sidec); if(sidea==sideb && sideb==sidec) //check whether all sides are equal { printf("This is an equilateral triangle.\n"); } else if(sidea==sideb || sidea==sidec || sideb==sidec) //check whether two sides are equal { printf("This is an isosceles triangle.\n"); } else //check whether no sides are equal { printf("This is a scalene triangle.\n"); } return 0; }

Sample Output:

Input three sides of triangle: 50 50 60 This is an isosceles triangle.

Flowchart:

How many scenario will you write to check whether its an equilateral triangle or not ?( triangle with equal sides?

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.
Next: Write a C 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.

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.

Test IDabcExpected OutputProgram OutputTested Outcome
1155IsoscelesIsoscelesPass
2255IsoscelesIsoscelesPass
3955IsoscelesIsoscelesPass
41055Not a TriangleNot a TrianglePass
5515IsoscelesIsoscelesPass
6525IsoscelesIsoscelesPass
7595IsoscelesIsoscelesPass
85105Not a TriangleNot a TrianglePass
9551IsoscelesIsoscelesPass
10552IsoscelesIsoscelesPass
11559IsoscelesIsoscelesPass
125510Not a TriangleNot a TrianglePass
13555EquilateralEquilateralPass

Testing Result of the Program

Not a Triangle

How many scenario will you write to check whether its an equilateral triangle or not ?( triangle with equal sides?

Equilateral triangle

How many scenario will you write to check whether its an equilateral triangle or not ?( triangle with equal sides?

Isosceles Triangle

How many scenario will you write to check whether its an equilateral triangle or not ?( triangle with equal sides?