We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6
Program 1
Triangle Program The Triangle Problem Problem Statement
The triangle program accepts three integers, a, b, and c, as input. These
are taken to be sides of a triangle. The integers a, b, and c must satisfy the following conditions: c1. 1 ≤ a ≤ 200 c4. a < b + c c2. 1 ≤ b ≤ 200 c5. b < a + c c3. 1 ≤ c ≤ 200 c6. c < a + b The output of the program is the type of triangle determined by the three sides: Equilateral, Isosceles, Scalene, or NotATriangle. If an input value fails any of conditions c1, c2, or c3, the program notes this with an output message, for example, “Value of b is not in the range of permitted values.” If values of a, b, and c satisfy conditions c4, c5, and c6, one of four mutually exclusive outputs is given:
1. If all three sides are equal, the program output is Equilateral.
2. If exactly one pair of sides is equal, the program output is Isosceles. 3. If no pair of sides is equal, the program output is Scalene. 4. If any of conditions c4, c5, and c6 is not met, the program output is NotATriangle. Program triangle’ Dim a, b, c As Integer The Dim c1, c2, c3, IsATriangle As Boolean pseudocode ‘Step 1: Get Input Do Output(“Enter 3 integers which are sides of a triangle”) Input(a, b, c) c1 = (1 ≤ a) AND (a ≤ 200) c2 = (1 ≤ b) AND (b ≤ 200) c3 = (1 ≤ c) AND (c ≤ 200) If NOT(c1) Then Output(“Value of a is not in the range of permitted values”) EndIf If NOT(c2) Then Output(“Value of b is not in the range of permitted values”) EndIf If NOT(c3) Then Output(“Value of c is not in the range of permitted values”) EndIf Until c1 AND c2 AND c3 Output(“Side A is”,a) Output(“Side B is”,b) Output(“Side C is”,c) ‘Step 2: Is A Triangle? If (a < b + c) AND (b < a + c) AND (c < a + b) Then IsATriangle = True Else IsATriangle = False EndIf ‘Step 3: Determine Triangle Type If IsATriangle Then If (a = b) AND (b = c) Then Output (“Equilateral”) Else If (a ≠ b) AND (a ≠ c) AND (b ≠ c) Then Output (“Scalene”) Else Output (“Isosceles”) EndIf EndIf Else Output(“Not a Triangle”) EndIf End triangle