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。

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

技术教程推荐

持续交付36讲 -〔王潇俊〕

Android开发高手课 -〔张绍文〕

Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕

分布式数据库30讲 -〔王磊〕

流程型组织15讲 -〔蒋伟良〕

说透数字化转型 -〔付晓岩〕

程序员的个人财富课 -〔王喆〕

朱涛 · Kotlin编程第一课 -〔朱涛〕

JavaScript进阶实战课 -〔石川〕

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