C++ 取整函数

 1 #include  <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int N = 110;
 6 
 7 signed main()
 8 {
 9     cout << ceil(1.0 * 9 / 2) << endl;     //向上取整
10     cout << floor(1.0 * 9 / 2) << endl;    //向下取整
11     cout << round(1.0 * 5 / 10) << endl;   //四舍五入
12     cout << round(1.0 * 4 / 10) << endl;
13     /*
14     5
15     4
16     1
17     0
18     */
19     return 0;
20 }

 

posted @ 2022-02-18 16:03  std&ice  阅读(227)  评论(0编辑  收藏  举报