Check whether two numbers are in silver ratio | C ++ implementation to check whether two numbers are in silver ratio with each other ; Function to check that two numbers are in silver 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 silver ratio ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checksilverRatio ( float a , float b ) { if ( a < b ) swap ( a , b ) ; float ratio1 = ( ( a / b ) * 1000.0 ) / 1000.0 ; float ratio2 = ( int ) ( ( ( 2 * a + b ) / a ) * 1000 ) ; ratio2 = ratio2 / 1000 ; if ( ratio1 == ratio2 && ( int ) ( ratio1 - 2.414 ) == 0 ) { cout << " Yes STRNEWLINE " ; return true ; } else { cout << " No STRNEWLINE " ; return false ; } } int main ( ) { float a = 2.414 ; float b = 1 ; checksilverRatio ( a , b ) ; }