c语⾔中round函数_round()函数以及C++中的⽰例
c语⾔中round函数
C ++ round()函数 (C++ round() function)
cmath header, it is used to round the given value that is nearest to the number round() function
round() function is a library function of cmath
with halfway cases rounded away from zero, it accepts a number and returns rounded value.
round()函数是cmath
cmath标头的库函数,⽤于对最接近该数字的给定值进⾏四舍五⼊,⼀半的情况下舍⼊为零,它接受⼀个数字并返回四舍round()函数
五⼊的值。
Syntax of round() function:
round()函数的语法:
round(x);
Parameter(s):
Parameter(s): x – is the number to round nearest to zero with halfway cases.
参数: x –是中途取整的数字,最接近零。
参数:
Return value: double – it returns double type value that is the rounded value of the number x.
Return value:
返回值:
返回值: double-返回double类型的值,该值是数字x的舍⼊值。
Example:
例:
int函数与round函数Input:
float x = 2.3;
Function call:
round(x);
Output:
2
Input:
float x = 2.8;
Function call:
round(x);
Output:
3
C ++代码演⽰round()函数的⽰例 (C++ code to demonstrate the example of round() function)
// C++ code to demonstrate the example of
// round() function
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
float x;
x = 15.3;
cout<<"round("<<x<<"): "<<round(x)<<endl;
x = 15.5;
cout<<"round("<<x<<"): "<<round(x)<<endl;
x = 15.8;
cout<<"round("<<x<<"): "<<round(x)<<endl;
x = -15.3;
cout<<"round("<<x<<"): "<<round(x)<<endl;
x = -15.5;
cout<<"round("<<x<<"): "<<round(x)<<endl;
x = -15.8;
cout<<"round("<<x<<"): "<<round(x)<<endl;
return 0;
}
Output
输出量
round(15.3): 15
round(15.5): 16
round(15.8): 16
round(-15.3): -15
round(-15.5): -16
round(-15.8): -16
翻译⾃:
c语⾔中round函数
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论