Related Articles

# ratio_less_equal() function in C++

• Last Updated : 09 Aug, 2021

The ratio_less_equal() is an inbuilt function in C++ which checks if the ratio R1 is less than or equal to the ratio R2. It returns True if the ratio is less than or equal to ratio 2, else it returns false.
Syntax:

`template < class ratio1_name, class ratio2_name > ratio_less_equal`

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 less than or equal to the ratio2 otherwise returns false.
Below programs illustrates the above function:
Program 1:

## CPP

 `// C++ program to illustrate the``// ratio_less_equal function``// when both the ratios are equal``#include ``#include ``using` `namespace` `std;``int` `main()``{``    ``typedef` `ratio<3, 9> ratio1;``    ``typedef` `ratio<1, 3> ratio2;` `    ``// check if R1<=R2``    ``if` `(ratio_less_equal::value)``        ``cout << ``"3/9 is less than or equal to 1/3"``;``    ``else``        ``cout << ``"3/9 is greater than 1/3"``;` `    ``return` `0;``}`
Output:
`3/9 is less than or equal to 1/3`

Program 2:

## CPP

 `// C++ program to illustrate the``// ratio_less_equal function``// to show less than``#include ``#include ``using` `namespace` `std;``int` `main()``{``    ``typedef` `ratio<1, 3> ratio1;``    ``typedef` `ratio<1, 2> ratio2;` `    ``// check if R1<=R2``    ``if` `(ratio_less_equal::value)``        ``cout << ``"1/3 is less than or equal to 1/2"``;``    ``else``        ``cout << ``"1/3 is greater than 1/2"``;` `    ``return` `0;``}`
Output:
`1/3 is less than or equal to 1/2`

Program 3:

## CPP

 `// C++ program to illustrate the``// ratio_less_equal function``// to show when greater than``#include ``#include ``using` `namespace` `std;``int` `main()``{``    ``typedef` `ratio<1, 8> ratio1;``    ``typedef` `ratio<1, 10> ratio2;` `    ``// check if R1<=R2``    ``if` `(ratio_less_equal::value)``        ``cout << ``"1/8 is less than or equal to 1/10"``;``    ``else``        ``cout << ``"1/8 is greater than 1/10"``;` `    ``return` `0;``}`
Output:
`1/8 is greater than 1/10`

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up