- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given two ratios i.e. x:y and y:z. Our task is to create a *Program to find the common ratio of three numbers in C++*.

**Problem Description** − We need to find the common ratio of three numbers using the ratios given to us. Using x:y and y:z, we will find x:y:z.

**Let’s take an example to understand the problem,**

3:5 8:9

24: 40: 45

**Explanation** − We have x:y and y:z, two different ratios. To create x:y:z, we will make y same in both ratios that will make the ratio possible. To do so, we will cross multiply.

$\frac{\square}{\square1} =\frac{\square2}{\square}\Rightarrow\frac{\square\square2}{\square1\square2}=\frac{\square1\square2}{\square2\square}$

This will make the ratio x’:y’:z’

So, 3*8 : 8*5 : 5*9 = 24 : 40 : 45 is the ratio.

As discussed in the above example, we need to make the middle element common for both the ratios. And for this, we will do cross-multiplication but sometimes cross multiplication might make the result larger. So, an efficient approach would be to find the LCM. And then finding the ratio as −

$\frac{\square*\square\square\square}{\square1}:\square\square\square:\frac{\square*\square\square\square}{\square2}$

**Program to illustrate the working of our solution,**

#include <iostream> using namespace std; int calcLcm(int a, int b){ int lcm = 2; while(lcm <= a*b) { if( lcm%a==0 && lcm%b==0 ) { return lcm; break; } lcm++; } return 0; } void calcThreeProportion(int x, int y1, int y2, int z){ int lcm = calcLcm(y1, y2); cout<<((x*lcm)/y1)<<" : "<<lcm<<" : "<<((z*lcm)/y2); } int main() { int x = 12, y1 = 15, y2 = 9, z = 16; cout<<"The ratios are\t"<<" x:y = "<<x<<":"<<y1<<"\ty:z = "<<y2<<":"<<z<<endl; cout<<"The common ratio of three numbers is\t"; calcThreeProportion(x, y1, y2, z); return 0; }

The ratios are x:y = 12:15 y:z = 9:16 The common ratio of three numbers is 36 : 45 : 80

- Related Questions & Answers
- C# program to find the maximum of three numbers
- C# program to find common elements in three sorted arrays
- Python program to find the maximum of three numbers
- C# program to find common elements in three arrays using sets
- C program to Find the Largest Number Among Three Numbers
- Java program to find maximum of three numbers
- Program to find largest of three numbers - JavaScript
- C++ Program to Find Largest Number Among Three Numbers
- Program to find HCF (Highest Common Factor) of 2 Numbers in C++
- Python program to find common elements in three sorted arrays?
- Java program to find common elements in three sorted arrays
- Program to find length of longest common subsequence of three strings in Python
- C++ Program for the Common Divisors of Two Numbers?
- Find common elements in three linked lists in C++
- Find common elements in three sorted arrays in C++

Advertisements