作业帮 > 综合 > 作业

用Delphi设计一个程序,从键盘输入a,b,c3个整数,将它们按照从大到小的次序输出

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/07 05:10:58
用Delphi设计一个程序,从键盘输入a,b,c3个整数,将它们按照从大到小的次序输出
请用Delphi编写,运行成功后请截下图.
//uses math;//为了它的使用max 和min 函数;//在public处,添加一个自定义排序函数sort,原型为:function sort(a:integer;b:integer;c:integer):string;实现如下:function TForm1.sort(a, b, c: integer): string;var  d:array[0..2] of integer;  temp,one,two,three,f:integer;begin// 取得a,b,c三个数的最大值,存入one中  temp:=max(a,b);  one:=max(temp,c);//取得三个数的最小值,存入three中  temp:=min(a,b);  three:=min(temp,c);//下面是为了取得第二大的数  d[0]:=a;  d[1]:=b;  d[2]:=c; for f:= 0 to 2 do  begin    if (one>d[f]) and (d[f]>three) then //取出处于中间的那个数,存入two中    begin      two:=d[f];    end;  end;  result:=inttostr(one)+'>'+inttostr(two)+'>'+inttostr(three);//输入结果end;//调用时,在界面那里放一个Button,三个edit,用于输入你的三个整数,再放入一个label,用于显示结果label1.Caption:=sort(strToInt(edit1.text),strtoInt(edit2.text),strtoInt(edit3.text));//代码有点长,希望对你有帮助.
再问: 可以语音么 我没有弄成功 呵呵、 我刚刚学 不好的地方请见谅啊
再答: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,math; //math添加进这里 type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } function sort(a:integer;b:integer;c:integer):string; //定义一个排列三个数大小的函数 end; var Form1: TForm1; implementation {$R *.dfm} { TForm1 } function TForm1.sort(a, b, c: integer): string; var d:array[0..2] of integer; temp,one,two,three,f:integer; begin // 取得a,b,c三个数的最大值,存入one中 temp:=max(a,b); one:=max(temp,c); //取得三个数的最小值,存入three中 temp:=min(a,b); three:=min(temp,c); //下面是为了取得第二大的数 d[0]:=a; d[1]:=b; d[2]:=c; for f:= 0 to 2 do begin if (one>d[f]) and (d[f]>three) then //取出处于中间的那个数,存入two中 begin two:=d[f]; end; end; result:=inttostr(one)+'>'+inttostr(two)+'>'+inttostr(three);//输入结果 end; procedure TForm1.FormCreate(Sender: TObject); begin edit1.Text:='100'; edit2.Text:='200'; edit3.text:='150'; end; procedure TForm1.Button1Click(Sender: TObject); begin label1.Caption:=sort(strToInt(edit1.text),strtoInt(edit2.text),strtoInt(edit3.text)); end; end. // 单元所有的文件如上,你可以自己再参考一下