isgreater()函数确定函数中给定的第一个参数的值是否大于第二个参数的值。如果第一个数字较大,则返回1,否则返回0。
考虑两个数字“ x”和“ y”。语法为:
bool isgreater(float x, float y); bool isgreater(double x, double y); bool isgreater(long double x, long double y); bool isgreater(Arithmetic x, Arithmetic y);
x,y :我们要比较的值。
参数(x,y) | 返回值 |
---|---|
x>y | 1 |
x |
0 |
让我们看一个简单的示例,其中x和y都是相同的类型。
#include <iostream> #include<math.h> using namespace std; int main() { float x=9.0; float y=7.0; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"isgreater(x,y) : "<<isgreater(x,y); return 0; }
输出:
Values of x and y are : 9.0,7.0 isgreater(x,y) : 1
在此示例中,isgreater()函数确定x的值大于y。因此,它返回1。
让我们看一个简单的示例,其中x和y都是不同的类型。
#include <iostream> #include<math.h> using namespace std; int main() { double x=45.4; char y='c'; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"isgreater(x,y) : "<<isgreater(x,y); return 0; }
输出:
Values of x and y are : 45.4,c isgreater(x,y) : 0
在此示例中,isgreater()函数确定x的值小于y,因为ASCII值" c"大于x的值。因此,它返回0。
让我们看一个简单的例子,当x等于NAN时。
#include <iostream> #include<math.h> using namespace std; int main() { double x=0.0/0.0; double y=12.3; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"isgreater(x,y) : "<<isgreater(x,y); return 0; }
输出:
Values of x and y are : nan , 12.3 isgreater(x,y) : 0
在此的示例x的值为NAN。因此,该函数返回0。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕