Count Odd and Even numbers in a range from L to R | Return the number of odd numbers in the range [ L , R ] ; if either R or L is odd ; Driver code
< ? php function countOdd ( $ L , $ R ) { $ N = ( $ R - $ L ) / 2 ; if ( $ R % 2 != 0 $ L % 2 != 0 ) $ N ++ ; return $ N ; } $ L = 3 ; $ R = 7 ; $ odds = countOdd ( $ L , $ R ) ; $ evens = ( $ R - $ L + 1 ) - $ odds ; echo " Count ▁ of ▁ odd ▁ numbers ▁ is ▁ " . $ odds . " STRNEWLINE " ; echo " Count ▁ of ▁ even ▁ numbers ▁ is ▁ " . $ evens ; ? >