islessgreater()函数确定第一个参数的值是小于还是大于第二个参数的值。如果第一个参数的值小于或大于第二个参数,则返回1,否则返回0。
Consider two numbers 'x' and 'y'. 语法 would be:
bool islessgreater(float x, float y); bool islessgreater(double x, double y); bool islessgreater(long double x, long double y); bool islessgreater(Arithmetic x, Arithmetic y);
(x,y):我们要比较的值。
参数 | 返回值 |
---|---|
x>y or x |
1 |
x=y or x=nan or y=nan | 0 |
让我们看一个简单的例子,当x和y相等时。
#include <iostream> #include<math.h> using namespace std; int main() { float x=1.2; float y=1.2; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"islessgreater(x,y) : "<<islessgreater(x,y); return 0; }
输出:
Values of x and y are : 1.2,1.2 islessgreater(x,y) : 0
在此示例中,x和y的值相等。因此,该函数返回0。
让我们看一个简单的示例,其中x和y属于不同类型并且不相等。
#include <iostream> #include<math.h> using namespace std; int main() { int x=7; float y=3.2; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"islessgreater(x,y) : "<<islessgreater(x,y); return 0; }
输出:
Values of x and y are : 7,3.2 islessgreater(x,y) : 1
在此示例中,x的值大于y的值。因此,该函数返回1。
让我们看一个简单的例子,当x的值为NAN时。
#include <iostream> #include<math.h> using namespace std; int main() { float x=0.0/0.0; float y=3.2; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"islessgreater(x,y) : "<<islessgreater(x,y); return 0; }
输出:
Values of x and y are : nan,3.2 islessgreater(x,y) : 0
在此示例中,x的值为NAN。因此,该函数返回0。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-islessgreater-function.html
来源:LearnFk无涯教程网
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)