lround()函数以及C ++中的示例
C++lround()函数
lround()函数是cmath标头的库函数,用于舍入给定的值并将其转换为长整数,它接受一个数字并返回最接近该数字的整数(长int)值(有中途情况))。
lround()函数语法:
lround(x);
参数:x–是中途取整的数字,最接近零。
返回值:longint–返回longint类型值,该值是数字x的舍入值。
示例
Input:
float x = 2.3;
Function call:
lround(x);
Output:
2
Input:
float x = 2.8;
Function call:
lround(x);
Output:
3C++代码演示lround()函数示例
//示例
//lround()功能
#include <iostream>
#include <cmath>
using namespace std;
//main()部分
int main(){
float x;
x = 15.3;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;
x = 15.5;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;
x = 15.8;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;
x = -15.3;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;
x = -15.5;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;
x = -15.8;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;
return 0;
}输出结果
lround(15.3): 15 lround(15.5): 16 lround(15.8): 16 lround(-15.3): -15 lround(-15.5): -16 lround(-15.8): -16
热门推荐
10 下雪拜年祝福语简短英语
11 食堂阿姨退休祝福语简短
12 年后同事聚餐祝福语简短
13 写生日祝福语简短唯美
14 疫情高考父母祝福语简短
15 酒店求婚文案祝福语简短
16 幽默的伴郎祝福语简短
17 空军婚礼祝福语简短
18 歌词朋友结婚祝福语简短