Find the n | function to calculate nth number made of even digits only ; variable to note how many such numbers have been found till now ; bool variable to check if 1 , 3 , 5 , 7 , 9 is there or not ; checking each digit of the number ; If 1 , 3 , 5 , 7 , 9 is found temp is changed to false ; temp is true it means that it does not have 1 , 3 , 5 , 7 , 9 ; If nth such number is found return it ; Driver Code
< ? php function findNthEvenDigitNumber ( $ n ) { $ count = 0 ; for ( $ i = 0 ; ; $ i ++ ) { $ curr = $ i ; $ isCurrEvenDigit = true ; while ( $ curr != 0 ) { if ( $ curr % 10 == 1 $ curr % 10 == 3 $ curr % 10 == 5 $ curr % 10 == 7 $ curr % 10 == 9 ) $ isCurrEvenDigit = false ; $ curr = $ curr / 10 ; } if ( $ isCurrEvenDigit == true ) $ count ++ ; if ( $ count == $ n ) return $ i ; } } echo findNthEvenDigitNumber ( 2 ) , " STRNEWLINE " ; echo findNthEvenDigitNumber ( 10 ) ; ? >