Largest N digit Octal number which is a Perfect square | C ++ implementation to find the maximum N - digit octal number which is perfect square ; Function to convert decimal number to a octal number ; Array to store octal number ; Counter for octal number array ; Store remainder in octal array ; Print octal number array in reverse order ; Largest n - digit perfect square ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void decToOctal ( int n ) { int octalNum [ 100 ] ; int i = 0 ; while ( n != 0 ) { octalNum [ i ] = n % 8 ; n = n / 8 ; i ++ ; } for ( int j = i - 1 ; j >= 0 ; j -- ) cout << octalNum [ j ] ; cout << " STRNEWLINE " ; } void nDigitPerfectSquares ( int n ) { int decimal = pow ( ceil ( sqrt ( pow ( 8 , n ) ) ) - 1 , 2 ) ; decToOctal ( decimal ) ; } int main ( ) { int n = 2 ; nDigitPerfectSquares ( n ) ; return 0 ; }