IT ken
IT ken

Reputation: 5

Writing algorithm for types of triangle

I am faced with a question that goes like this:

Write an algorithm that reads three integers a, b, c representing the sides of a triangle.
Next, print the type of triangle represented (scalene, equilateral, isosceles).
Assume a valid triangle is represented.

I would like some feedback on the errors that my algorithm may present or what I can do to improve how sequential it is:

step 1)  Start
step 2)  Declare int a,b,c
step 3)  Prompt a,b,c
step 4)  Read a,b,c
step 5)  If (a<>b and b<>c and c<>a) then
step 6)  Print "Scalene Triangle"
step 7)  Elseif((a=b and a != c) or (a=c and a!=b) or (b=c and b!=a))
step 8)  Print "Isoceles Triangle"
step 9)  Elseif ((a=b & b!=c ) or (a=c & c!=b) or (b=c & c!=a)) then
step 10) Print "Equilateral Triangle"
step 11) Endif
step 12) Stop

Upvotes: 0

Views: 11300

Answers (2)

Zeeshan Rafique
Zeeshan Rafique

Reputation: 56

There are 4 types of Triangles

Consider A , B and C as 3 sides possible triangle then

  1. Isosceles -> If (A equals B and not equals C) OR (B equals C and not equals A)
  2. Scalene -> If A not equals B not equals C (All sides different)
  3. Equilateral -> If A equals B equals C ( All sides equal)
  4. Not a Triangle -> If sum of any two sides is less than equal to the thirds side A + B less than equals C OR C + A less than equals B OR C + B less than equals A

Upvotes: 1

RE60K
RE60K

Reputation: 621

You'll get equilateral triangle as an isoceles triangle too,so change it to:

  • ...
  • If ((a=b & b!=c ) or (a=c & c!=b) or (b=c & c!=a)) then
  • Print "Scalene Triangle"
  • ...

Upvotes: 0

Related Questions