大家好 初学pascal 这个if语句练习题 为什么编译不过
正确的书写是怎样的 ?
另外可否推荐一两本入门的教材
program ex26;var a,b,c,p,s:real;begin
readln(a,b,c);
if a+b > c then
if a+c > b then
if c+b > a then
begin
p := (a+b+c)/2;
s := sqrt(p*(p-a)*(p-b)*(p-c)); write('s=',s);
end
else
write('cant');
else
write('cant');
else
write('cant');
readln
end.
正确的书写是怎样的 ?
另外可否推荐一两本入门的教材
program ex26;var a,b,c,p,s:real;begin
readln(a,b,c);
if a+b > c then
if a+c > b then
if c+b > a then
begin
p := (a+b+c)/2;
s := sqrt(p*(p-a)*(p-b)*(p-c)); write('s=',s);
end
else
write('cant');
else
write('cant');
else
write('cant');
readln
end.
解决方案 »
- delphi 一个窗体上 是不是 adoconnection 越多越好 分的越细越好
- fastreport 难题,各位大侠帮帮,先给50',解决后再给150’
- 奇怪的PChar问题
- 人不能没有理想,从今天起决定用D8写一个和CSDN类似的论坛,希望熟悉WEB编程的人来指教和交流!
- 500分求平衡二叉树的相关源码.. 谢谢~
- 如何实现定时关机的程序
- Delphi中用ADOCommand控件写SQL语句怎么给程序中定义的变量附值
- 请问哪里有rational rose下载?
- 《结束标记'body'与开始标记'html'不匹配》是怎么回事?
- Money类型小数位怎样达到3位以上?
- delphi 怎么填写网页的生日选择表
- 取硬盘卷标.发到idtcpserver上乱码
上一行加上个end;
现在写成这样就可以了 不过不太明白为什么会这样 pascal 还是没C写的好看program ex26;var a,b,c,p,s:real;begin
readln(a,b,c);
if a+b > c then
if a+c > b then
if c+b > a then
begin
p := (a+b+c)/2;
s := sqrt(p*(p-a)*(p-b)*(p-c)); write('s=',s);
end
else
write('cant')
else
write('cant')
else
write('cant');
readln
end.
begin
p := (a+b+c)/2;
s := sqrt(p*(p-a)*(p-b)*(p-c));
write('s=',s);
end
else
write('cant');有那三个数能满足这个条件呢?
program ex26;var a,b,c,p,s:real;begin
readln(a,b,c);
if a+b > c then
if a+c > b then
if c+b > a then
begin
p := (a+b+c)/2;
s := sqrt(p*(p-a)*(p-b)*(p-c)); write('s=',s);
end
else
write('cant')
end;
else
write('cant')
end;
else
write('cant');
readln
end;
end;
end.
其实就这样而已,看来你要去看多点基础语法先。结贴给分吧................
注意最后的分号,else前的语句1不能有分号。如果不用begin..end括住,else会找最近的if 配对。你可以用下面的简单程序,用不同的 a , b, c的值进行测试。
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,p,s :real;
begin
a := 8;
b := 5;
c := 2;
if a+b > c then //if 1
if a+c > b then //if 2
if c+b > a then //if 3
begin
p := (a+b+c)/2;
s := sqrt(p*(p-a)*(p-b)*(p-c));
showmessage('s='+floattostr(s));
end
else //else 3
showmessage('cant(c+b<=a)')
else //else 2
showmessage('cant(a+c<=b)')
else //else 1
showmessage('cant(a+b<=c)');
end;