C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math ceil()

C++ Math ceil()

将值四舍五入为不小于给定值的最接近的整数。
例如:
ceil(8.1)=9.0;
ceil(-8.8)=-8.0;

语法

假设数字为" x"。语法为:
double ceil(double x);

参数

x : 将其舍入为最接近的整数的值。

返回值

它返回不小于x的最小整数值。

示例1

让我们看一个简单的示例,考虑正值的x。
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
  float x=9.2;
  std::cout << "Initial value of x is :"<<x;
  cout<<'\n';
  cout<<"final value of x is :"<<ceil(x);
  return 0;
}
输出:
Initial value of x is :9.2
final value of x is :10   

示例2

让我们看一个简单的示例,考虑x的负值。
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
  float x=-2.2;
  std::cout << "Initial value of x is :"<<x;
  cout<<'\n';
  cout<<"final value of x is :"<<ceil(x);
  return 0;
}
输出:
Initial value of x is :-2.2
final value of x is :-2   

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4