text: Squares of numbers with repeated single digits | Set 1 ( 3 , 6 and 9 ) | Function to find the square of 333. . .333 , 666. . .666 and 999. . .999 ; if the number is 333. . .333 ; if the number is 666. . .666 ; if the number is 999. . .999 ; variable for hold result ; find the no of digit ; add size - 1 time a in result ; add one time b in result ; add size - 1 time c in result ; add one time d in result ; return result ; Drivers code ; find square of 33. .33 ; find square of 66. .66 ; find square of 66. .66
code: < ? php function find_Square_369 ( $ num ) { if ( $ num [ 0 ] == '3' ) { $ a = '1' ; $ b = '0' ; $ c = '8' ; $ d = '9' ; } else if ( $ num [ 0 ] == '6' ) { $ a = '4' ; $ b = '3' ; $ c = '5' ; $ d = '6' ; } else { $ a = '9' ; $ b = '8' ; $ c = '0' ; $ d = '1' ; } $ result = " " ; $ size = strlen ( $ num ) ; for ( $ i = 1 ; $ i < $ size ; $ i ++ ) $ result = $ result . $ a ; $ result = $ result . $ b ; for ( $ i = 1 ; $ i < $ size ; $ i ++ ) $ result = $ result . $ c ; $ result = $ result . $ d ; return $ result ; } $ num_3 = "3333" ; $ num_6 = "6666" ; $ num_9 = "9999" ; $ result = " " ; $ result = find_Square_369 ( $ num_3 ) ; echo " Square ▁ of ▁ " . $ num_3 . " ▁ is ▁ : ▁ " . $ result . " STRNEWLINE " ; $ result = find_Square_369 ( $ num_6 ) ; echo " Square ▁ of ▁ " . $ num_6 . " ▁ is ▁ : ▁ " . $ result . " STRNEWLINE " ; $ result = find_Square_369 ( $ num_9 ) ; echo " Square ▁ of ▁ " . $ num_9 . " ▁ is ▁ : ▁ " . $ result . " STRNEWLINE " ; return 0 ; ? >