
Patrick B. answered 07/21/19
Math and computer tutor/teacher
Not very clear as to what the program is supposed to do....
If you want to TEST to see if the three sides given are a right triangle then it is easy.
All it is :
if A*A + B*B = C*C then
writeln(' YES, it is a right triangle by pythagorean theorem ')
else
writeln(' No it is not a right triangle');
end;
Otherwise, READ ON..............
====================================================================
program PythagoreanTriangle (input,output);
function Pythagorean ( X,y : real; hypotenuse_flag: integer): real;
var A,B,C : real;
var returnResult : real;
begin
if hypotenuse_flag=1 then
begin
A:=x; C:=y;
B := sqrt(C*C - A*A);
returnResult := B;
end
else begin
A:=x; B:=y;
C:= sqrt(A*A+B*B);
returnResult := C;
end;
Pythagorean := returnResult;
end;
Procedure DoPythagorean ( xDummy,yDummy : real; iHypotenuseFlag : integer) ;
var zDummy : real;
var A,B,C : real;
begin
if iHypotenuseFlag=1 then
begin
zDummy := Pythagorean(xDummy,yDummy,iHypotenuseFlag);
A:=xDummy; B:=zDummy; C:=yDummy;
end
else begin
zDummy := Pythagorean(xDummy,yDummy,iHypotenuseFlag);
A:=xDummy; B:=yDummy; C:=zDummy;
end;
writeln('***************************');
writeln(' leg A = ',A:12:6);
writeln(' leg B = ',B:12:6);
writeln(' hypotenuse C = ',C:12:6);
end;
begin {main}
DoPythagorean(5,13,1); { leg=5, hypotenuse=13, so other leg is 12 }
DoPythagorean(3,4,0); { leg A = 3, leg B=4, so hypotenuse is 5 }
DoPythagorean(2,2.82842712474619,1); {leg A = 2, hypotenuse is sqrt(8), so leg B = 2}
DoPythagorean(3,5,0); { leg A = 3, leg B = 5, so hypotenuse is sqrt(34)= 5.83095... }
end.