Check perfect square using addition / subtraction | This function returns true if n is perfect square , else false ; sum is sum of all odd numbers . i is used one by one hold odd numbers ; Driver code
< ? php function isPerfectSquare ( $ n ) { for ( $ sum = 0 , $ i = 1 ; $ sum < $ n ; $ i += 2 ) { $ sum += $ i ; if ( $ sum == $ n ) return true ; } return false ; } if ( isPerfectSquare ( 35 ) ) echo " Yes STRNEWLINE " ; else echo " No STRNEWLINE " ; if ( isPerfectSquare ( 49 ) ) echo " Yes STRNEWLINE " ; else echo " No STRNEWLINE " ; ? >