南宁建站方案,网页设计心得体会300,在阿里云做的网站怎么移动,南阳网站seo浮点数转换为整数四舍五入Given a float value and we have to round the value to the nearest integer with the help of Macro in C language. 给定一个浮点值#xff0c;我们必须借助C语言中的Macro将其舍入到最接近的整数。 Macro Definition: 宏定义#xff1a; #def…浮点数转换为整数四舍五入Given a float value and we have to round the value to the nearest integer with the help of Macro in C language. 给定一个浮点值我们必须借助C语言中的Macro将其舍入到最接近的整数。 Macro Definition: 宏定义 #define round(x) ((x)0?(long)((x)0.5):(long)((x)-0.5))
Example: 例 Input:
float val110.00f;
float val210.23f;
float val310.50f;
float val410.65f;
Output:
After round val110
After round val210
After round val311
After round val411
Program: 程序 #include stdio.h
//Macro
#define round(x) ((x)0?(long)((x)0.5):(long)((x)-0.5))
//Main code
int main(void)
{
float val110.00f;
float val210.23f;
float val310.50f;
float val410.65f;
printf(After round val1%d\n,round(val1));
printf(After round val2%d\n,round(val2));
printf(After round val3%d\n,round(val3));
printf(After round val4%d\n,round(val4));
return 0;
}
Output 输出量 After round val110
After round val210
After round val311
After round val411
翻译自: https://www.includehelp.com/c-programs/define-a-macro-to-round-a-float-value-to-nearest-integer-in-c.aspx浮点数转换为整数四舍五入