如何在不使用 cmath 的情况下获得 double 类型的两个输入的下限: 如果第一个输入为负数,这就是它的工作原理,但对于正整数则不起作用,不知道哪里出了问题?任何见解表示赞赏..谢谢
int main()
{
floors=floor(n1);
cout<< " The floor of value 1 is " <<floors<<endl;
floors=floor(n2);
cout<<" The floor of value 2 is " <<floors<<endl;
long floor(long f)
{
if( (f+ 0.5) >= (int(f)-1) )
return int (f)-1;
else
return int (f);
}
最佳答案
将其更改为:
long floor(double f)
{
if( f >= 0.0 ) {
return int(f);
} else {
return ( int(f) - 1 );
}
}
关于c++ - 如何在不使用 cmath 的情况下返回数字的上限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13037767/