一个简单的运算函数(送分题)
求1个函数 功能很简单
功能:A=1000 B=1~1000 让A随机加或减B
[解决办法]
不知道楼主是否要求这个样子的函数:
- Delphi(Pascal) code
function RandCal(A, B: Integer): Integer;begin Randomize; if Random(1) = 1 then Result := A + B else Result := A - B;end;
[解决办法]
B=1~1000 也要随机吗?
- Delphi(Pascal) code
function RandCal(A: Integer): Integer;var B: Integer;begin Randomize; B := Random(999) + 1; if Random(1) = 1 then Result := A + B else Result := A - B;end;
[解决办法]
最后个问题如果B是100-1000之间呢
=============================
B := Random(900) + 100;