# ratio_equal() in C++ with examples

The ratio_equal() is an inbuilt function in C++ STL that checks if two given ratios are equal or not.

Syntax:

```template < class ratio1_name, class ratio2_name > ratio_equal
```

Template Parameters: The function accepts two template parameters ratio1 and ratio2 which are to be compared.

Return value: The function returns true if the ratios are equal otherwise it returns false.

Below programs illustrate the ratio_equal() function:

Program 1:

 `// C++ program to illustrate the ` `// ratio_equal function ` `#include ` `#include ` `using` `namespace` `std; ` `int` `main() ` `{ ` `    ``typedef` `ratio<3, 9> ratio1; ` `    ``typedef` `ratio<1, 3> ratio2; ` ` `  `    ``// If both the ratios are same ` `    ``if` `(ratio_equal::value) ` `        ``cout << ``"Both ratio are equal"``; ` `    ``else` `        ``cout << ``"Both ratio are not equal"``; ` ` `  `    ``return` `0; ` `} `

Output:

```Both ratio are equal
```

Program 2:

 `// C++ program to illustrate the ` `// ratio_equal function ` `#include ` `#include ` `using` `namespace` `std; ` `int` `main() ` `{ ` `    ``typedef` `ratio<1, 2> ratio1; ` `    ``typedef` `ratio<5, 4> ratio2; ` ` `  `    ``// If both the ratios are same ` `    ``if` `(ratio_equal::value) ` `        ``cout << ``"Both ratio are equal"``; ` `    ``else` `        ``cout << ``"Both ratio are not equal"``; ` ` `  `    ``return` `0; ` `} `

Output:

```Both ratio are not equal
```

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

1

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.