viết ct : bằng thủ tục kiểm tra xem 3 số nguyên dương x y z có tạo thành tam giác vuôn g k
2 câu trả lời
program TG_vuong;
uses crt;
var x,y,z:integer;
{---Thu-tuc---}
procedure tg(x,y,z:integer);
var kt:boolean;
begin
kt:=true;
if (x<=0) or (y<=0) or (z<=0) then kt:=false;
if (x+y<=z) or (x+z<=y) or (y+z<=x) then kt:=false;
if kt=false then
begin
write('Khong phai tam giac');
exit;
end;
kt:=false;
if (x*x+y*y=z*z) or (x*x+z*z=y*y) or (y*y+z*z+x*x) then kt:=true;
if kt=false then write('Khong phai tam giac vuong')
else write('La tam giac vuong');
end;
{---CT-chinh---}
BEGIN
clrscr;
write('Nhap x: '); readln(x);
write('Nhap y: '); readln(y);
write('Nhap z: '); readln(z);
tg(x,y,z);
readln;
end.
uses crt;
var x,y,z:extended;
{---Thu-tuc-kiem-tra---}
procedure check(x,y,z:extended);
var check:boolean;
begin
if (x<=0) or (y<=0) or (z<=0) then
begin
check:=false;
write('Khong tao thanh tam giac'); exit;
end;
if (sqr(x)=sqr(y)+sqr(z)) or (sqr(y)=sqr(x)+sqr(z)) or (sqr(z)=sqr(x)+sqr(y)) then
begin
check:=true;
write('Co tao thanh tam giac vuong');
end
else begin
check:=false;
write('Khong tao thanh tam giac'); exit;
end;
end;
{---Chuong-trinh-chinh---}
BEGIN
clrscr;
write('Nhap 3 canh tam giac: '); readln(x,y,z);
check(x,y,z);
readln;
END.