Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

74 users online



[C] Question

[C] Question

Currently viewing this thread: 1 (0 members and 1 guests)


Nouko

Nouko

[Insert intelligent information about Nouko here]
Status: Offline!

[C] Question

Code:


int func(int x) {
int ans = 0;
while (x > 1) {
ans = ans + 1;
x = x / 2;
}
return ans;
}

That's the problem, the answer is ln(x), x being whatever value you entered for "x". How to you come to the answer though.

Last edited by akuma, February 5th, 2003 11:03 PM (Edited 1 times)

drnemo

drnemo

Status: Offline!

i hate c and i don't know if this works for c also (it works for c++):

// callinf the function
func(x, ans);

void func(int x, int &ans)
{
while (x > 1)
{
ans++; // is the same as ans = ans +1
x /= 2; // is the same as x = x /2
}
}

that is it! ans will be changed in the main function because it is the address of ans!

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0064 seconds.