triangle problem – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sat, 16 Mar 2024 10:00:33 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg triangle problem – Programmerbay https://programmerbay.com 32 32 C Program To Check whether Triangle is Equilateral, Isosceles or Scalene https://programmerbay.com/c-program-to-classify-a-triangle/ https://programmerbay.com/c-program-to-classify-a-triangle/#respond Sun, 21 Aug 2022 16:33:46 +0000 https://programmerbay.com/?p=5308 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.

type of triangle

  1. Equilateral Triangle: A triangle in which all sides are of the same length
  2. Isosceles Triangle: A triangle in which exactly two sides are equal
  3. Scalene Triangle: A triangle in which all sides are having different length

Approach to determine the type of a triangle

  1. Read the length of a triangle for the user
  2. If side1, side2 and side3 are equal to each other, then
    • print a message the triangle is an equilateral triangle
  3.  If any two from side1, side2 or side3 are having the same length, then
    • print message the triangle is isosceles triangle
  4.  If all three sides are different in length, then
    • print message the triangle is a scalene triangle

C Program To Check whether Triangle is Equilateral, Isosceles or Scalene

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 ();
}

 

Testing Result of the Program

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

 

]]>
https://programmerbay.com/c-program-to-classify-a-triangle/feed/ 0
Design the test cases and test the program of Triangle Problem by using Data Flow testing https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-data-flow-testing/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-data-flow-testing/#respond Sat, 23 Nov 2019 10:15:05 +0000 https://programmerbay.com/?p=5505 In this article, we will formulate test cases for triangle problems using data flow testing in such a way that all the du and dc paths get covered. The first step is to generate flow graph from the code ( Here’s the code).

Same as path testing make flow graph.

path testing practical problem 1

Now, make Decision-to-Decision table in which consecutive nodes are counted as an individual.

path testing practical problem

On the basis of above table, create DD graph.

path testing practical problem 2

After DD graph, it is time to figure out du and dc paths. For this, create ‘ defined node and used at node’ table to view variable’s definition and initialization.

data flow testing triangle problem

From above table, find du and dc paths.

data flow testing triangle problem 1

Based on du and dc paths create test cases, covering each and every variable definition and usage.

Test IDabcExpected OutputProgram OutputTested Outcome
15105Not a triangleInvalid InputFail
21095Scalene triangleScalene trianglePass
3515Isosceles triangleIsosceles trianglePass
4555Equilateral TriangleEquilateral TrianglePass
5-155Invalid InputInvalid InputPass

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-data-flow-testing/feed/ 0
Design the test cases and test the program of Triangle problem by using Path testing https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-path-testing/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-path-testing/#respond Fri, 22 Nov 2019 19:02:40 +0000 https://programmerbay.com/?p=5473 In this type of testing, test cases are drived by considering all the independent paths of the DD graph.

Here’s is the triangle problem code.

In path testing, first we create the flow graph of the triangle problem based on the program which shows the flow and possible paths.

path testing practical problem 1

Once the flow graph is created, with the help of it list all the consecutive nodes and assign an alphabet to them.path testing practical problem

After creating DD Table, it’s time to generate DD graph through which Cyclomatic complexity and the possible path will be gathered.

path testing practical problem 2

Using DD graph ( Decision to Decision graph ), calculate the cyclomatic complexity which tells all the independent paths.

Cyclomatic complexity = E – N + 2P

= 20-16+2

=6

Possbile paths are:

-A,B,C,D,E,F,G,K,L,M,O,P
-A,B,C,D,E,F,H,I,K,L,M,O,P
-A,B,C,D,E,F,H,J,K,L,M,O,P
-A,B,C,D,K,L,M,O,P
-A,B,C,D,K,L,M,N,O,P
-A,B,K,L,M,O,P

Based on these paths, we will create Test cases.

Test IDabcExpected OutputProgram OutputTested Outcome
15105Not a triangleInvalid InputFail
21095Scalene triangleScalene trianglePass
3515Isosceles triangleIsosceles trianglePass
4555Equilateral TriangleEquilateral TrianglePass
5-155Invalid InputInvalid InputPass
65511Invalid InputInvalid InputPass

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-path-testing/feed/ 0
Design the test cases and test the program of Triangle Problem by using Decision Table Based testing https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-decision-table-based-testing/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-decision-table-based-testing/#respond Fri, 27 Sep 2019 07:36:47 +0000 https://programmerbay.com/?p=5397 Program

If you’re curious to see the “Triangle Problem “ code, then the link is here with tested test cases.

Decision Table Based Testing

In Decision table based testing,  Condition stubs and Action stubs are viewed as inputs and outputs. Here, we’ll be applying this Structural testing technique to create test cases:

Let’s create the decision table first,

new dtbt

On the basis of above decision table, we have these test cases for testing:

Test IDabcExpected OutputProgram OutputTested Outcome
15105Not a triangleNot a trianglePass
21055Not a triangleNot a trianglePass
35510Not a triangleNot a trianglePass
41095Scalene triangleScalene trianglePass
5515Isosceles triangleIsosceles trianglePass
6155Isosceles triangleIsosceles trianglePass
7---Not PossibleNot Possible
8551Isosceles triangleIsosceles trianglePass
9---Not PossibleNot Possible
10---Not PossibleNot Possible
11555Equilateral TriangleEquilateral TrianglePass

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-decision-table-based-testing/feed/ 0
Design the test cases and test the program of Triangle problem by using Equivalence Class testing https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-equivalence-class-testing/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-equivalence-class-testing/#respond Sat, 21 Sep 2019 16:55:39 +0000 https://programmerbay.com/?p=5283 You can check out the “Triangle problem” program along with its tested test cases here.

In triangle problem, we require to identify output and input domain.

Output Domain:

O1 = Not a triangle, when any of the sides is greater than the sum of the other
O2 = Equilateral Triangle
O3 = Isosceles Triangle
O4 = Scalene Triangle

Input Domain:
I1 = { 0< a <= 10 }
I2 = { a<0 }
I3 = { a>10 }
I4 = { 0< b <= 10 }
I5= { b<0 }
I6 = { b>10 }
I7 = { 0< c <= 10 }
I8 = { c<0 }
I9 = { c>10 }

Further, on the basis of sides equality and whether the sum of the two sides are equal or greater, we can create classes.
I10 = { a=b=c }
I11 = { a=b, b!=c }
I12 = { b=c, c!=a }
I13 = { a=c, c!=b }
I14 = { a!=b!=c }
I15 = { a+b = c }
I16 = { a+b < c }
I17 = { b+c = a }
I18 = { b+c < a }
I19 = { c+a = b }
I20 = { c+a >b }
There are 4 possible outcomes and 20 possible input classes, in total 24 test cases to test.

Here are the test cases and program tested results.

ClassesabcExpected OutputProgram OutputTested Outcome
O11055Not a TriangleNot a TrianglePass
O2555Equilateral TriangleEquilateral TrianglePass
O3155Isosceles TriangleIsosceles TrianglePass
O41095Scalene TriangleScalene TrianglePass
I1555Equilateral TriangleEquilateral TrianglePass
I2055Invalid InputInvalid InputPass
I31155Invalid InputInvalid InputPass
I4555Equilateral TriangleEquilateral TrianglePass
I5505Invalid InputInvalid InputPass
I65115Invalid InputInvalid InputPass
I7555Equilateral TriangleEquilateral TrianglePass
I8550Invalid InputInvalid InputPass
I95511Invalid Input
.
Invalid InputPass
I10555Equilateral TriangleEquilateral TrianglePass
I11551Isosceles TriangleIsosceles TrianglePass
I12155Isosceles TriangleIsosceles TrianglePass
I13515Isosceles TriangleIsosceles TrianglePass
I149510Scalene TriangleScalene TrianglePass
I155510Not a TriangleNot a TrianglePass
I161510Not a TriangleNot a TrianglePass
I171055Not a TriangleNot a TrianglePass
I181051Not a TriangleNot a TrianglePass
I195105Not a TriangleNot a TrianglePass
I205101Not a TriangleNot a TrianglePass

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-equivalence-class-testing/feed/ 0
Design the test cases and test the program of Triangle problem by using Robustness Testing https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-robustness-testing/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-robustness-testing/#respond Thu, 19 Sep 2019 18:24:35 +0000 https://programmerbay.com/?p=5234 A polygon with 3 sides having any of the side greater than the sum of its other two sides cannot be considered as triangle. On the basis of sides, a triangle can be categorized in isosceles, equilateral and scalene triangle.

An isosceles triangle is a triangle in which two sides are equal.

An equilateral triangle is a triangle in which all sides are equal.

A scalene triangle is a triangle in which no two sides are equivalent to one other.

Program:

Here you can find  “Triangle problem” program along with its tested output.

Robustness Testing

We are assuming interval [1,10] for creating test cases and we will generate test cases using Robustness testing accordingly.

In Robustness Testing, 6N+1 test cases will be generated, which means, in this case, 6*3+1 = 19 test cases.

Test IDabcExpected OutputProgram OutputTested Outcome
1055Invalid InputInvalid InputPass
2155IsoscelesIsoscelesPass
3255IsoscelesIsoscelesPass
4955IsoscelesIsoscelesPass
51055Not a TriangleNot a TrianglePass
61155Invalid InputInvalid InputPass
7505Invalid InputInvalid InputPass
8515IsoscelesIsoscelesPass
9525IsoscelesIsoscelesPass
10595IsoscelesIsoscelesPass
115105Not a TriangleNot a TrianglePass
125115Invalid InputInvalid InputPass
13550Invalid InputInvalid InputPass
14551IsoscelesIsoscelesPass
15552IsoscelesIsoscelesPass
16559IsoscelesIsoscelesPass
175510Not a TriangleNot a TrianglePass
185511Invalid InputInvalid InputPass
19555EquilateralEquilateralPass

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-robustness-testing/feed/ 0
Design the test cases and test the program of Triangle problem by using Boundary Value Analysis https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-boundary-value-analysis/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-boundary-value-analysis/#respond Thu, 19 Sep 2019 16:44:14 +0000 https://programmerbay.com/?p=5233 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

triangle problem 2

Equilateral triangle

triangle problem 1

Isosceles Triangle

triangle problem

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-triangle-problem-by-using-boundary-value-analysis/feed/ 0