- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find the common ratio of three numbers in C++
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,
Input
3:5 8:9
Output
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.
This will make the ratio x’:y’:z’
So, 3*8 : 8*5 : 5*9 = 24 : 40 : 45 is the ratio.
Program to illustrate the working of our solution,
Example
#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; }
Output
The ratios are x:y = 12:15 y:z = 9:16 The common ratio of three numbers is 36 : 45 : 80
- Related Articles
- C# program to find the maximum of three numbers
- C# program to find common elements in three sorted arrays
- C# program to find common elements in three arrays using sets
- Program to find HCF (Highest Common Factor) of 2 Numbers in C++
- C program to Find the Largest Number Among Three Numbers
- Python program to find the maximum of three numbers
- C++ Program to Find Largest Number Among Three Numbers
- Java program to find maximum of three numbers
- Program to find largest of three numbers - JavaScript
- 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?
- Python program to find common elements in three lists using sets
- Swift Program to Find the Largest Among Three Numbers

Advertisements