(* istriangle.pas - Given the lengths of 3 line segments, see if they can * form a triangle. The rule is that the longest has to be shorter than the * sum of the other two sides. But first, we must determine which line * segment is the longest. This program illustrates the if-then statement. *) program istriangle; var a, b, c, longest, leg1, leg2 : integer; begin (* Input *) writeln('Let''s see if you really have a triangle.'); write('Enter side 1: '); readln(a); write('Enter side 2: '); readln(b); write('Enter side 3: '); readln(c); (* Calculations... * We first determine which side is the longest, and call it longest. * The other two sides will be called leg1 and leg2. *) if (a > b) and (a > c) then begin longest := a; leg1 := b; leg2 := c; end else if (b > a) and (b > c) then begin longest := b; leg1 := a; leg2 := c; end else begin longest := c; leg1 := a; leg2 := b; end; (* Test for being a real triangle. *) if longest < leg1 + leg2 then writeln('Yes, this is a triangle.') else writeln('No, the three sides cannot form a triangle.'); end.