Given a number N in decimal base , find number of its digits in any base ( base b ) | C ++ program to Find Number of digits in base b . ; function to print number of digits ; Calculating log using base changing property and then taking it floor and then adding 1. ; printing output ; Driver method ; taking inputs ; calling the method
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void findNumberOfDigits ( long n , int base ) { int dig = ( int ) ( floor ( log ( n ) / log ( base ) ) + 1 ) ; cout << " The ▁ Number ▁ of ▁ digits ▁ of ▁ " << " Number ▁ " << n << " ▁ in ▁ base ▁ " << base << " ▁ is ▁ " << dig ; } int main ( ) { long n = 1446 ; int base = 7 ; findNumberOfDigits ( n , base ) ; return 0 ; }