[Webinar] Streamline your web hosting managementRegister Today

x
Solved

# Log(n) algorithm

Posted on 2000-01-31
Medium Priority
302 Views
Hi there. Is there and algorithm that involves successive division so can
log(n) be computed?
0
• 10
• 4
• 2

LVL 11

Expert Comment

ID: 2476263
For integers or floats?

..B ekiM
0

Author Comment

ID: 2476425
for integers now
0

Author Comment

ID: 2476610
make it for floats if it can be
0

Author Comment

ID: 2476908
0

Author Comment

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

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

Author Comment

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

LVL 11

Expert Comment

ID: 2478653
> so it really works?

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

..B ekiM
0

Author Comment

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

ID: 2480661
0

LVL 11

Accepted Solution

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

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

ID: 2483065
Do you have further questions?

..B ekiM
0

Author Comment

ID: 2483375
can it be made to work with any number?
0

LVL 85

Expert Comment

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

Author Comment

ID: 2486007
Any number if possible
0

## Featured Post

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
Course of the Month10 days, 23 hours left to enroll