isgreater(x,y)函数详解

首页 / C++入门教程 / isgreater(x,y)函数详解

isgreater()函数确定函数中给定的第一个参数的值是否大于第二个参数的值。如果第一个数字较大,则返回1,否则返回0。

Note:如果函数的一个或两个参数均为NAN,则返回0。

isgreater - 语法

考虑两个数字“ 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);

Note: 算术类型可以是任何类型。它可以是float,double,long double,int或char。如果任何参数是整数类型,则将其强制转换为double。

isgreater - 参数

x,y :我们要比较的值。

isgreater - 返回值

参数(x,y) 返回值
x>y 1
x 0

isgreater - 例子1

让我们看一个简单的示例,其中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。

isgreater - 例子2

让我们看一个简单的示例,其中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。

isgreater - 例子3

让我们看一个简单的例子,当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。

无涯教程网

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

从0开始学微服务 -〔胡忠想〕

TensorFlow快速入门与实战 -〔彭靖田〕

Serverless入门课 -〔蒲松洋(秦粤)〕

分布式系统案例课 -〔杨波〕

跟月影学可视化 -〔月影〕

爱上跑步 -〔钱亮〕

技术面试官识人手册 -〔熊燚(四火)〕

爆款文案修炼手册 -〔乐剑峰〕

给程序员的写作课 -〔高磊〕

好记忆不如烂笔头。留下您的足迹吧 :)