Largest proper fraction with sum of numerator and denominator equal to a given number | PHP program to find the largest fraction a / b such that a + b is equal to given number and a < b . ; Calculate N / 2 ; ; Check if N is odd or even ; If N is odd answer will be ceil ( n / 2 ) - 1 and floor ( n / 2 ) + 1 ; If N is even check if N / 2 i . e a is even or odd ; If N / 2 is even apply the previous formula ; If N / 2 is odd answer will be ceil ( N / 2 ) - 2 and floor ( N / 2 ) + 2 ; driver function
< ? php function solve ( $ n ) { $ a = ( float ) $ n / 2 ; if ( $ n % 2 != 0 ) echo ceil ( $ a ) - 1 , " ▁ " , floor ( $ a ) + 1 , " STRNEWLINE " ; else { if ( $ a % 2 == 0 ) { echo ceil ( $ a ) - 1 , " ▁ " , floor ( $ a ) + 1 , " STRNEWLINE " ; } else { echo ceil ( $ a ) - 2 , " ▁ " , floor ( $ a ) + 2 , " STRNEWLINE " ; } } } $ n = 34 ; solve ( $ n ) ; ? >