procedure TForm1.Button2Click(Sender: TObject); var x:real; n:Integer; begin x:=sqrt(n*1.0); showmessage(floattostr(x)); end;
x:=int(sqrt(n*1.0));还是错误的。。 x:=sqrt(n*1.0)叶还错误
不行啊,用两种都说说Integer和Extended不兼容错误。
Var i,x:Integer; begin //x:=n div 2; x:=sqrt(n*1.0); ////这里了。错误 for i:=1 to x do if n div i=0 then begin
真服了你;你定义成INTEGER了X; Var i,x:Integer;//////X应该是REAL类型
我要用的就是Integer的X嘛。。是Real型的话,我下面的for循环就用不了x了。
或者Real刑怎么变成Integer型也可以。。
Returns the value of X rounded to the nearest whole number.UnitSystemCategoryarithmetic routinesDelphi syntax:function Round(X: Extended): Int64;DescriptionIn Delphi, the Round function rounds a real-type value to an integer-type value.X is a real-type expression. Round returns an Int64 value that is the value of X rounded to the nearest whole number. If X is exactly halfway between two whole numbers, the result is always the even number. This method of rounding is often called "Banker抯 Rounding".If the rounded value of X is not within the Int64 range, a runtime error is generated, which can be handled using the EInvalidOp exception.Note: The behavior of Round can be affected by the Set8087CW procedure or SetRoundMode function.
var
x:real;
n:Integer;
begin
x:=sqrt(n*1.0);
showmessage(floattostr(x));
end;
x:=sqrt(n*1.0)叶还错误
begin
//x:=n div 2;
x:=sqrt(n*1.0); ////这里了。错误
for i:=1 to x do
if n div i=0 then
begin
Var i,x:Integer;//////X应该是REAL类型