text: Squares of numbers with repeated single digits | Set 1 ( 3 , 6 and 9 ) | C ++ program to find square of these large numbers ; 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: #include <iostream> NEW_LINE using namespace std ; string find_Square_369 ( string num ) { char a , b , c , d ; 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' ; string result = " " ; int size = num . size ( ) ; for ( int i = 1 ; i < num . size ( ) ; i ++ ) result += a ; result += b ; for ( int i = 1 ; i < num . size ( ) ; i ++ ) result += c ; result += d ; return result ; } int main ( ) { string num_3 , num_6 , num_9 ; num_3 = "3333" ; num_6 = "6666" ; num_9 = "9999" ; string result = " " ; result = find_Square_369 ( num_3 ) ; cout << " Square ▁ of ▁ " << num_3 << " ▁ is ▁ : ▁ " << result << endl ; result = find_Square_369 ( num_6 ) ; cout << " Square ▁ of ▁ " << num_6 << " ▁ is ▁ : ▁ " << result << endl ; result = find_Square_369 ( num_9 ) ; cout << " Square ▁ of ▁ " << num_9 << " ▁ is ▁ : ▁ " << result << endl ; return 0 ; }