用Delphi设计一个程序,从键盘输入a,b,c3个整数,将它们按照从大到小的次序输出
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/07 05:10:58
用Delphi设计一个程序,从键盘输入a,b,c3个整数,将它们按照从大到小的次序输出
请用Delphi编写,运行成功后请截下图.
请用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. // 单元所有的文件如上,你可以自己再参考一下
再问: 可以语音么 我没有弄成功 呵呵、 我刚刚学 不好的地方请见谅啊
再答: 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. // 单元所有的文件如上,你可以自己再参考一下
用Delphi设计一个程序,从键盘输入a,b,c3个整数,将它们按照从大到小的次序输出
设计一个C ++程序,从键盘输入a b c 三个整数,将他们从大到小依次输出
设计一个java程序,从键盘输入三个整数,按照从小到大的顺序输出
通过键盘输入一个含有10个整数的数列.编写程序,将10个整数按照从大到小的顺序重新排列,要求输出排序
用Java语言设计一个程序,从键盘输入3个整数,按照从小到大的顺序输出.是用Java语言哦,
输入4个整数a,b,c,d,编写程序,将它们按从大到小的顺序输出
1、假设通过键盘输入一个含有10个整数的数列.编写程序,将10个整数按照从大到小的顺序重新排列,要求输出排序后的结果以及
编写一个C程序,要求从键盘输入三个整数a,b,c,输出其中最大的数.
从键盘输入三个整数a、b、c,要求将输出的数据按从大到小排序后输出 输入 从键盘上输入三个整数a
从键盘输入10个整数,把它们从大到小排序后输出
有4个由用户任意输入的整数a,b,c和d,要求按照从大到小的顺序输出 写出程序
c语言程序设计:设变量a、b、c分别存放从键盘输入的3个整数.编写程序,按从大到小的顺序排列这3个整数.