
pascal的简单程序问题。
programtest;vara,b,c:integer;beginread(a,b);if(a<=31)and(a>0)thenbeginif(b>999)thenwr...
program test;
var a,b,c:integer;
begin
read(a,b);
if(a<=31)and(a>0) then
begin
if(b>999)
then write('cuowu');
end
else
begin
if(b<=999)and(b>=100)then c:=1000*a+b else
if(b<=99) and (b>=10)then c:=100*a+b else
if(b<=9 ) and (b >=1)then c:=10*a+b
write(c);
end
else write('cuowu');
end.
哪有错误?? 展开
var a,b,c:integer;
begin
read(a,b);
if(a<=31)and(a>0) then
begin
if(b>999)
then write('cuowu');
end
else
begin
if(b<=999)and(b>=100)then c:=1000*a+b else
if(b<=99) and (b>=10)then c:=100*a+b else
if(b<=9 ) and (b >=1)then c:=10*a+b
write(c);
end
else write('cuowu');
end.
哪有错误?? 展开
2个回答
展开全部
LZ的错误有两处。
第一处:
if(b<=999)and(b>=100)then c:=1000*a+b else
if(b<=99) and (b>=10)then c:=100*a+b else
if(b<=9 ) and (b >=1)then c:=10*a+b
write(c);
这个地方,if(b<=9 ) and (b >=1)then c:=10*a+b最后要加上分号,即 if(b<=9 ) and (b >=1)then c:=10*a+b;
第二处,请LZ注意自己语句的逻辑关系,
if(a<=31)and(a>0) then
begin
if(b>999)
then write('cuowu');
end
这一句你用一个BEGIN END结束了 if(b>999) then write('cuowu'); 的逻辑关系,所以,下面紧接着的ELSE表示不满足条件if(a<=31)and(a>0)。这样的话,也就说你的程序中主体部分中只有1个IF语句,但你在程序的结尾 else write('cuowu');请LZ自己看看,这个ELSE是没有IF语句在前面作为条件语句的,所以最后这句else write('cuowu');是多余的。
解决的办法:LZ要么把最后一句ELSE WRITE直接删除,要么就把这句
if(a<=31)and(a>0) then
begin
if(b>999)
then write('cuowu');
end
改成
if(a<=31)and(a>0) then
if(b>999) then write('cuowu')
else
这两种改法都可以,当然,实际运行时候的结果是完全不同的,因为逻辑顺序都不同
第一处:
if(b<=999)and(b>=100)then c:=1000*a+b else
if(b<=99) and (b>=10)then c:=100*a+b else
if(b<=9 ) and (b >=1)then c:=10*a+b
write(c);
这个地方,if(b<=9 ) and (b >=1)then c:=10*a+b最后要加上分号,即 if(b<=9 ) and (b >=1)then c:=10*a+b;
第二处,请LZ注意自己语句的逻辑关系,
if(a<=31)and(a>0) then
begin
if(b>999)
then write('cuowu');
end
这一句你用一个BEGIN END结束了 if(b>999) then write('cuowu'); 的逻辑关系,所以,下面紧接着的ELSE表示不满足条件if(a<=31)and(a>0)。这样的话,也就说你的程序中主体部分中只有1个IF语句,但你在程序的结尾 else write('cuowu');请LZ自己看看,这个ELSE是没有IF语句在前面作为条件语句的,所以最后这句else write('cuowu');是多余的。
解决的办法:LZ要么把最后一句ELSE WRITE直接删除,要么就把这句
if(a<=31)and(a>0) then
begin
if(b>999)
then write('cuowu');
end
改成
if(a<=31)and(a>0) then
if(b>999) then write('cuowu')
else
这两种改法都可以,当然,实际运行时候的结果是完全不同的,因为逻辑顺序都不同

2023-06-12 广告
单片机,即单片微控制器,也称为单片微型计算机,是将中央处理器(CPU)、存储器(ROM,RAM)、输入/输出接口和其他功能部件集成在一块 在一个小块的集成电路上,从而实现对整个电路或系统的数字式控制。单片机不是完成某一个逻辑功能的芯片,而是...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
展开全部
var a,b,c:integer;
begin
read(a,b);
if(a>31)or(a<1)or(b>999)or(b<1) then write('cuowu')
else begin
if (b>=100)then c:=1000*a+b
else if (b>=10)then c:=100*a+b
else if (b>=1)then c:=10*a+b;
write(c);
end;
end.
其实输出就一句:write(a,b);就够了,不用c出场,即:
var a,b:integer;
begin
read(a,b);
if(a>31)or(a<1)or(b>999)or(b<1) then write('cuowu')
else write(a,b);
end.
begin
read(a,b);
if(a>31)or(a<1)or(b>999)or(b<1) then write('cuowu')
else begin
if (b>=100)then c:=1000*a+b
else if (b>=10)then c:=100*a+b
else if (b>=1)then c:=10*a+b;
write(c);
end;
end.
其实输出就一句:write(a,b);就够了,不用c出场,即:
var a,b:integer;
begin
read(a,b);
if(a>31)or(a<1)or(b>999)or(b<1) then write('cuowu')
else write(a,b);
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询