C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math isgreater()

C++ Math isgreater()

isgreater()函数确定函数中给定的第一个参数的值是否大于第二个参数的值。如果第一个数字较大,则返回1,否则返回0。
注意: 如果函数的一个或两个参数均为NAN,则它将返回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);
注意: 算术类型可以是任何类型。它可以是float,double,long double,int或char。如果任何参数是整数类型,则将其强制转换为double。

参数

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

返回值

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

示例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、

示例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
在此示例中,由于ASCII值" c"大于x的值,isgreater()函数确定x的值小于y。因此,它返回0。

示例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。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4