pascal 编程 : 用编程找出1000以内的一个数,大了输g,小了输l,对了输r,猜10次以内

用折中解决,要找出这个数,这个数要输入,用while语句
2024-12-30 06:59:24
推荐回答(3个)
回答1:

这游戏我编过
var
a1,a2,a3:longint;
begin
a1:=10;
randomize;
a2:=random(1001);
while (a2<>a3)and(a1<>0) do
begin
write('you has',a1);
if a1<>1 then write('s');
write(' times!!!');
readln(a3);
a1:=a1-1;
if a3=a2 then writeln('r') else
if a3end;
if a3=a2 then write('congratulation!!!') else write('sorry,you lose,this number is ',a2,'!!');
readln;
end.

回答2:

var
a,b,i:integer
begin
a:=random(1000)+1;
while i<10 do
begin
i:=i+1;
readln(b);
if b>a then writeln('g')
if a>b then writeln('l')
if a=b then writeln('r');
end;
if i=10 then writeln('You are loser',' The answer is ',a);
end.

回答3:

var
a,b,i:integer
begin
a:=random(1000)+1;
for i:=1 to 10 do
begin
readln(b);
if b>a then writeln('g')
else if a>b then writeln('l')
else if a=b then writeln('r');
end;
end.