Program to find the common ratio of three numbers | Utility function ; Function to print a : b : c ; To print the given proportion in simplest form . ; Get the ratios Get ratio a : b1 ; Get ratio b2 : c ; Find the ratio a : b : c
< ? php function __gcd ( $ a , $ b ) { return $ b == 0 ? $ a : __gcd ( $ b , $ a % $ b ) ; } function solveProportion ( $ a , $ b1 , $ b2 , $ c ) { $ A = $ a * $ b2 ; $ B = $ b1 * $ b2 ; $ C = $ b1 * $ c ; $ gcd = __gcd ( __gcd ( $ A , $ B ) , $ C ) ; echo ( $ A / $ gcd ) . " : " . ( $ B / $ gcd ) . " : " . ( $ C / $ gcd ) ; } $ a = 3 ; $ b1 = 4 ; $ b2 = 8 ; $ c = 9 ; solveProportion ( $ a , $ b1 , $ b2 , $ c ) ; ? >