//通用算法 procedure TForm1.Button1Click(Sender: TObject); var i:integer; MyArray:array of single; index:single; begin setlength(myarray,9); for I:=0 to 4 do myarray[i]:=i; for I:=1 to 4 do if myarray[i-1]>myarray[i] then begin index:=myarray[i-1]; myarray[i-1]:=myarray[i]; myarray[i]:=index; end; showmessage('最大的数为:'+floattostr(myarray[4])); end;
同意cooling(cooling)的方法,数据结构里讲过的
c语言算法 int intArray[]={4,5,6,2,6}; int temp; for (int i=0;i<intArray.length();i++) { if (i==0) { temp=intArray[0]; continue; } if (intArray[i]>temp) temp=intArray[i]; } return temp ; //最大值 }
Max(A, Max(B, Max(C, Max(D, E))));
uses
Math;var
maxv: Integer;
begin
maxv := Max(A, Max(B, Max(C, Max(D, E))));
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
MyArray:array of single;
index:single;
begin
setlength(myarray,9);
for I:=0 to 4 do
myarray[i]:=i;
for I:=1 to 4 do
if myarray[i-1]>myarray[i] then
begin
index:=myarray[i-1];
myarray[i-1]:=myarray[i];
myarray[i]:=index;
end;
showmessage('最大的数为:'+floattostr(myarray[4]));
end;
int intArray[]={4,5,6,2,6};
int temp;
for (int i=0;i<intArray.length();i++)
{
if (i==0)
{
temp=intArray[0];
continue;
}
if (intArray[i]>temp)
temp=intArray[i];
}
return temp ; //最大值
}