第一题 Problem 42641. MATLAB Basic: rounding
Do rounding near to zero
Example: -8.8, answer -8
+8.1 answer 8
想0四舍五入,即如果是正值,就向下取整(floor),如果是负值,就向上取整(ceil)
function y = round_zero(x)
if x<0
y=ceil(x);
else
y=floor(x);
end
end
第二题 Problem 42642. MATLAB Basic: rounding II
Do rounding nearest integer.
Example: -8.8, answer -9
+8.1 answer 8
+8.50 answer 9
返回最近整数,直接用round
function y = round_x(x)
y=round(x);
end
第三题 Problem 42643. MATLAB Basic: rounding III
Do rounding towards minus infinity.
Example: -8.8, answer -9
+8.1 answer 8
+8.50 answer 8
向下取整
function


最低0.47元/天 解锁文章
613

被折叠的 条评论
为什么被折叠?



