Log(n) algorithm

Hi there. Is there and algorithm that involves successive division so can
log(n) be computed?
desperadoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikeblasCommented:
For integers or floats?

..B ekiM
0
desperadoAuthor Commented:
for integers now
0
desperadoAuthor Commented:
make it for floats if it can be
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

desperadoAuthor Commented:
Adjusted points to 65
0
desperadoAuthor Commented:
Does this work for what i want to do?

#include <iostream.h>
main()
{
  int numero,base;
  int ans=0;
 
  cout<<"Enter number and base: ";
  cin>>numero;
  cin>>base;
  while(numero>1)
  {
    numero=numero/base;
    ans++;
  }
cout<<"Logarithm of number you entered is: ";
cout<<ans<<"\n";
}





0
ozoCommented:
It works for at least one interpretation of what you want to do.
0
desperadoAuthor Commented:
So what changes do i have to do to it so it really works?
0
mikeblasCommented:
> so it really works?

I don't know. What's your definition of "really works"?

..B ekiM
0
desperadoAuthor Commented:
i need the program to calculate log n with succeddive divisions and want to know if the code i posted here works for that
0
desperadoAuthor Commented:
Adjusted points to 70
0
mikeblasCommented:
Your code only finds an integer exponent. If you wanted a floating point, it doesn't work. If integers only are OK, you're fine.

Your code doesn't work for n when n is less than one.  If you didn't really want that, you're OK.

It's up to you: do you need those things, or not?

Why can't you use the log() function? Why must you use sucessive division?

..B ekiM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
desperadoAuthor Commented:
well is a challenge doing it with successive divisions. So far i have only got the part I posted working but it only works for a range of numbers. I know floating point is not included in the code i made as well as other cases.Is like a kind of general algorithm for computing log.
0
mikeblasCommented:
Do you have further questions?

..B ekiM
0
desperadoAuthor Commented:
can it be made to work with any number?
0
ozoCommented:
With what number would you like it to work?
0
desperadoAuthor Commented:
Any number if possible
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.