Open In App

ratio_greater() function in C++

Last Updated : 26 Jul, 2018
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
The ratio_greater() is an inbuilt function in C++ which checks if the ratio R1 is greater than the ratio R2. It returns True if the ratio is greater than ratio 2, else it returns false. Syntax:
template < class ratio1_name, class ratio2_name > ratio_greater
Template Parameters The function accepts two template parameters ratio1 and ratio2 which are to be compared. Return value: The function returns a boolean value which is true if the ratio1 is greater than ratio2 otherwise it returns false. Below programs illustrates the above function: Program 1: CPP
// C++ program to illustrate the
// ratio_greater function
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
    typedef ratio<7, 7> ratio1;
    typedef ratio<4, 7> ratio2;

    // check if R1>R2
    if (ratio_greater<ratio1, ratio2>::value)
        cout << "7/7 is more than 4/7";
    else
        cout << "7/7 is not more than 4/7";

    return 0;
}
Output:
7/7 is more than 4/7
Program 2: CPP
// C++ program to illustrate the
// ratio_greater function
#include <iostream>
#include <ratio>
using namespace std;
int main()
{
    typedef ratio<1, 2> ratio1;
    typedef ratio<4, 7> ratio2;

    // check if R1>R2
    if (ratio_greater<ratio1, ratio2>::value)
        cout << "1/2 is more than 4/7";
    else
        cout << "1/2 is not more than 4/7";

    return 0;
}
Output:
1/2 is not more than 4/7

Article Tags :
Practice Tags :

Similar Reads