Check whether two numbers are in golden ratio | C ++ implementation to check whether two numbers are in golden ratio with each other ; Function to check that two numbers are in golden ratio ; Swapping the numbers such that A contains the maximum number between these numbers ; First Ratio ; Second Ratio ; Condition to check that two numbers are in golden ratio ; Driver code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkGoldenRatio ( float a , float b ) { if ( a <= b ) { float temp = a ; a = b ; b = temp ; } std :: stringstream ratio1 ; ratio1 << std :: fixed << std :: setprecision ( 3 ) << ( a / b ) ; std :: stringstream ratio2 ; ratio2 << std :: fixed << std :: setprecision ( 3 ) << ( a + b ) / a ; if ( ( ratio1 . str ( ) == ratio2 . str ( ) ) && ratio1 . str ( ) == "1.618" ) { cout << " Yes " << endl ; return true ; } else { cout << " No " << endl ; return false ; } } int main ( ) { float a = 0.618 ; float b = 1 ; checkGoldenRatio ( a , b ) ; return 0 ; }