#include <iostream>
#include <cmath> // 引入cmath库以使用ceil函数
int main() {
double num = 4.3;
double result = ceil(num); // 使用ceil函数将num向上取整
std::cout << "The ceiling of " << num << " is " << result << std::endl;
num = -4.3;
result = ceil(num); // 对于负数,ceil函数会向0取整
std::cout << "The ceiling of " << num << " is " << result << std::endl;
return 0;
}
#include <cmath>:引入了C++标准库中的cmath库,该库包含了数学函数,如ceil。ceil(num):ceil函数用于返回不小于num的最小整数。对于正数,它会向上取整;对于负数,它会向0取整。上一篇:c++函数定义
下一篇:ffmpeg c++
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站