C program or source code that calculates and returns logarithm . For example, if n = 64, then your function should return 6, and if n = 129, then your function should return 7. Let us see how to use **C program** to find logarithm of number.

Following is a solution using recursion for C program to find logarithm of number.

#include<stdio.h> unsigned int Log2n(unsigned int n) { return (n > 1)? 1 + Log2n(n/2): 0; } int main() { unsigned int n = 32; printf("%u", Log2n(n)); getchar(); return 0; }

Let us try an extended version of the problem.

Writing a one line function Logn(n ,r) which returns . Following is the solution for the extended problem to C program to find logarithm of a number with any base.

#include<stdio.h> unsigned int Logn(unsigned int n, unsigned int r) { return (n > r-1)? 1 + Logn(n/r, r): 0; } int main() { unsigned int n = 256; unsigned int r = 4; printf("%u", Logn(n, r)); getchar(); return 0; }

Let us know if you face any issues in compiling the codes. Write in form of comments.

Regards for helping out, good information. “I have witnessed the softening of the hardest of hearts by a simple smile.” by Goldie Hawn.

I savour, result in I found just what I was having a look for. You’ve ended my 4 day long hunt! God Bless you man. Have a great day. Bye

chanel bags http://chanelbagssale.overblog.com/

This code will give you just the interger value. It will not return the decimal part.

I wondered about the ability to return a float value as well

Is there a way to return the full logarithmic decimal value using a recursion of this fashion?