Program to find the common ratio of three numbers | C ++ implementation of above approach ; Function to print a : b : c ; To print the given proportion in simplest form . ; Driver code ; Get the ratios ; Get ratio a : b1 ; Get ratio b2 : c ; Find the ratio a : b : c
#include <bits/stdc++.h> NEW_LINE using namespace std ; void solveProportion ( int a , int b1 , int b2 , int c ) { int A = a * b2 ; int B = b1 * b2 ; int C = b1 * c ; int gcd = __gcd ( __gcd ( A , B ) , C ) ; cout << A / gcd << " : " << B / gcd << " : " << C / gcd ; } int main ( ) { int a , b1 , b2 , c ; a = 3 ; b1 = 4 ; b2 = 8 ; c = 9 ; solveProportion ( a , b1 , b2 , c ) ; return 0 ; }