Be the first user to complete this post

  • 0
Add to List
Beginner

336. Calculate Logn base r – Java Implementation

Objective: Given a number n and r, write a program to calculate Logrn

Example:

N = 32, r =2
Log232= 5

N = 64, r = 4
Log464= 3

Approach:

Without using built-In function-

  • Initialize result = 0.
  • Keep dividing the given number by r till number is greater than 0 and add one to the result if n is greater than equal to 1.

Output:

Log64 with base 4 value: 3.0

Using built-In function-

  • Use Java built in function to compute.

Output:

Log64 with base 4 value: 3.0