Round()内置函数不适用于Turbo C ++ v4.0

时间:2016-01-12 10:31:23

标签: c++ turbo-c++

此round()不在math.h标题下。如何使它工作?

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float i=5.4;
printf("%f\t%f",i,round(i));
getch();
}

2 个答案:

答案 0 :(得分:2)

它不可用。您需要使用floorceil为自己编写。

但更好的是,获得最新的编译器。没有理由继续使用Turbo C ++,自1993年以来,语言和库的变化令人难以置信。

答案 1 :(得分:1)

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float f=5.4;
int rounded,k;
k=f//Initialising the value of k as the integral value of f
if((f-k)>=0.5)
{
 rounded = k+1;
}
else
{
 rounded = k;
}
printf("The rounded value is %d",rounded);
getch();
}
相关问题