Program to compute log a to any base b ( logb a ) | C ++ program to find log ( a ) on any base b using Recursion ; Recursive function to compute log a to the base b ; Driver code
#include <iostream> NEW_LINE using namespace std ; int log_a_to_base_b ( int a , int b ) { return ( a > b - 1 ) ? 1 + log_a_to_base_b ( a / b , b ) : 0 ; } int main ( ) { int a = 3 ; int b = 2 ; cout << log_a_to_base_b ( a , b ) << endl ; a = 256 ; b = 4 ; cout << log_a_to_base_b ( a , b ) << endl ; return 0 ; }