求四个数中的最大数

wxtang 2001-06-29 09:17:50
有a,b,c,d四个变量,当a不为最大时,就把a与最大的对调,
...全文
90 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bokei 2001-06-29
  • 打赏
  • 举报
回复
var
a,b,c,d,tmp,max:Integer;
Numbers:array [0..3] of PInteger //指针数组
begin
//assign a,b,c,d
.....

Numbers[0]=@a;
Numbers[1]=@b;
Numbers[2]=@c;
Numbers[3]=@d;

max:=0;
for i:=0 to 3 do
begin
if Numbers[i]^>Numbers[max]^ then max:=i;
end

tmp:=a;
a:=Numbers[max]^;
Numbers[max]^=tmp;
end;

end;
imchk6 2001-06-29
  • 打赏
  • 举报
回复
这种题目也敢拿出来, 不要太丢人了.
myxfang 2001-06-29
  • 打赏
  • 举报
回复
上面要加
uses math;
myxfang 2001-06-29
  • 打赏
  • 举报
回复
Var a,b,c,d,temp:real;
begin
a:=10.5;b:=9.5;c:=11.5;d:=12;
temp:=max(max(max(a,b),c),d);
if b=temp then b:=a
else if c=temp then c:=a
else if d=temp then d:=a;
a:=temp;
temp:=max(max(b,c),d);
if c=temp then c:=b
else if d=temp then d:=b;
b:=temp;
temp:=max(c,d);
if temp=d then d:=c;
c:=temp;
edit1.text:=floattostr(a);//最大
edit2.text:=floattostr(b);
edit3.text:=floattostr(c);
edit4.text:=floattostr(d);//最小
end;
wxtang 2001-06-29
  • 打赏
  • 举报
回复
我这样只能把最大的值赋给a,不能把a的值赋给最大的那个数,谁能帮我
wxtang 2001-06-29
  • 打赏
  • 举报
回复
procedure TForm7.Button1Click(Sender: TObject);
var
a,b,c,d,e,t1,t2,temp:real;
function largest(d1,d2,d3:real):real;
var
cul:real;
begin
if d1>d2 then cul:=d1 else cul:=d2;
if d3>cul then cul:=d3;
largest:=cul
end;
begin
t1:=largest(a,b,c);
t2:=largest(d,e,t1)
end;
begin
if a<t2 then
begin
temp:=t2; t2:=a;a:=temp;
end;
end;
edit1.text:=floattostr(a);
edit2.text:=floattostr(b);
edit3.text:=floattostr(c);
edit4.text:=floattostr(d);
end.

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧