信息学奥赛语言教程PASCAL函数表(2)
合肥奥数网整理
2012-12-13 14:11:36
截尾函数trunc(x)
定义:functionTrunc(X:Real):Longint;注意:X是实型表达式.Trunc返回Longint型的X的整数部分例子:
begin
Writeln(1.4,'becomes',Trunc(1.4));{1}
Writeln(1.5,'becomes',Trunc(1.5));{1}
Writeln(-1.4,'becomes',Trunc(-1.4));{-1}
Writeln(-1.5,'becomes',Trunc(-1.5));{-1}
end.
四舍五入函数round(x)
定义:functionRound(X:Real):Longint;注意:X是实型表达式.Round返回Longint型的X的四舍五入值.如果返回值超出了Longint的表示范围,则出错.例子:
begin
Writeln(1.4,'roundsto',Round(1.4));{1}
Writeln(1.5,'roundsto',Round(1.5));{2}
Writeln(-1.4,'roundsto',Round(-1.4));{-1}
Writeln(-1.5,'roundsto',Round(-1.5));{-2}
end.
下一页阅读:取小数函数、求平方根函数和平方函数