接受一个浮点数值,输出该数值的近似整数值。如果小数点后数值大于等于5,向上取整;小于5,则向下取整。
7.5 变为 8
7.2 变为 7
#include <stdlib.h>
#include <stdio.h>
int main()
{
/*float num,temp;
scanf("%f",&num);
temp = num - (int)num;
if (temp >= 0.5)
{
num += 1.0;
printf("%d\n", int(num));
}
else
printf("%d\n", int(num));*/
float num;
scanf("%f",&num);
int n = (int)(num+0.5);
printf("%d\n",n);
//system("pause");
return 0;
}
添加笔记