这个PASCAL程序哪里错了?(入门)

来源:百度知道 编辑:UC知道 时间:2024/05/26 13:07:25
输入三个正数,若能用这三个数作为边长组成三角形,就计算出三角形的周长,否则输出NO。(组成三角形的条件为:任意两边之和大于第三边)

program exdd;
VAR a,b,c,z:real;
begin
readln(a,b,c);
z:=a+b+c;
if ((a+b)>c) and ((a+c)>b) and ((c+b)>a) then writeln (z);
if ((a+b)<c) or ((a+c)<b) or ((c+b)<a) then writeln ('NO');
readln;
end.

有几点告诉楼主
1.你的程序和楼上的程序错在了没有考虑到某两条边相加等于第三边的情况
2.程序不够简洁

程序如下
program exdd;
var a,b,c:real;
begin
readln(a,b,c);
if ((a+b)>c) and ((a+c)>b) and ((c+b)>a) then writeln (a+b+c) else writeln('NO');
readln;
end.
你看,知识改了一下,既简洁,右正确
其实能拼成三角形就是符合任意两边之和大于第三边
既然这样,也就是不符合的就不能组成了
那何必再判断呢?
直接else就可以了嘛

program exdd;
VAR a,b,c,z:real;
begin
readln(a,b,c);
z:=a+b+c;
if ((a+b)>c) and ((a+c)>b) and ((c+b)>a) then writeln (z)//如果你想周长不是科学计数法的话,可以加:0:0
else writeln('NO');
//if ((a+b)<c) or ((a+c)<b) or ((c+b)<a) then writeln ('NO');
//如果相等呢?也是不行的,直接否则就输出no就行了
readln;
end.

把if ((a+b)<c) or ((a+c)<b) or ((c+b)<a) then writeln ('NO');改成else writeln('no');另外if ((a+b)>c) and ((a+c)>b) and ((c+b)>a) then writeln (z);后的分号去掉再把readln也去了,readln好像没什么作用。

我自己也做了个,你看看:
VAR a,b,c: