一、向上取整
例如:ceil(3.7)=4 ceil(5.2)=6 ceil(1.001)=2
#include<bits/stdc++.h> using namespace std; int main() { int ans; float s; while(cin>>s) { ans=ceil(s); cout<<ans<<endl; } return 0; }
讯享网
运行结果:
二、向下取整
例如:floor(3.1)=3 floor(5.9)=5 floor(1.99)=1
讯享网#include<bits/stdc++.h> using namespace std; int main() { int ans; float s; while(cin>>s) { ans=floor(s); cout<<ans<<endl; } return 0; }
运行结果:


三、四舍五入
例如:round(3.9)=4 round(4.2)=4 round(7.4)=7
#include<bits/stdc++.h> using namespace std; int main() { int ans; float s; while(cin>>s) { ans=round(s); cout<<ans<<endl; } return 0; }
运行结果:

当然了,每个函数的括号里也可以写一条语句,例如a/b,i+j等。
好了,那今天就到这里啦,感谢您的支持,有什么不懂的问题也可以写在评论区里,
我们下期再见吧(◕ᴗ◕✿),拜拜(。◕ˇ∀ˇ◕)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/127018.html