[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Log(n) algorithm

Posted on 2000-01-31
16
Medium Priority
?
302 Views
Last Modified: 2010-04-02
Hi there. Is there and algorithm that involves successive division so can
log(n) be computed?
0
Comment
Question by:desperado
  • 10
  • 4
  • 2
16 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 2476263
For integers or floats?

..B ekiM
0
 

Author Comment

by:desperado
ID: 2476425
for integers now
0
 

Author Comment

by:desperado
ID: 2476610
make it for floats if it can be
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:desperado
ID: 2476908
Adjusted points to 65
0
 

Author Comment

by:desperado
ID: 2476914
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
 
LVL 85

Expert Comment

by:ozo
ID: 2477264
It works for at least one interpretation of what you want to do.
0
 

Author Comment

by:desperado
ID: 2477958
So what changes do i have to do to it so it really works?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2478653
> so it really works?

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

..B ekiM
0
 

Author Comment

by:desperado
ID: 2480660
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
 

Author Comment

by:desperado
ID: 2480661
Adjusted points to 70
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 210 total points
ID: 2480926
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
 

Author Comment

by:desperado
ID: 2482901
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
 
LVL 11

Expert Comment

by:mikeblas
ID: 2483065
Do you have further questions?

..B ekiM
0
 

Author Comment

by:desperado
ID: 2483375
can it be made to work with any number?
0
 
LVL 85

Expert Comment

by:ozo
ID: 2483641
With what number would you like it to work?
0
 

Author Comment

by:desperado
ID: 2486007
Any number if possible
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question