exam query

ace333

Newcomer
Joined
Jul 19, 2005
Messages
22
was given this problem in an interview...

anyone got any ideas....

What initial values of a and c are required such that the final values of a and b are:


a = 32
b = 4

…

int a,b,c

a = ?
b = 0
c = ?

for( b=0; a<12; b++ )
{
a = (a+a) * c;
}
 
If I were given that in an interview I'd have asked "Seriously?" There's no point in giving that in an interview. If they said "Yes, seriously" then I'd have walked out.

-ner
 
IngisKahn said:
a = 2
c = -1


can i ask u how long it took u to do that or what way of thinking help u solve the problem,,, i feel so stupid, i've been looking at this for an hour
 
32 = 16ac^4
2 and 1 are the only integers that fit that equation and setting c to be negative flips the sign every other pass so that on the third iteration a is -16.

It's pretty straight forward but I agree with Nerseus that it is a completely ridiculous question.
 
Back
Top