Code help: n^2 > 12000

I need help writing a loop function. I need to use a while loop to find the smallest integer (n) so that n^2 > 12,000.

expl.

109 x 109 = 11881

110 x 110 = 12100

Therefore, 110 is the smallest value where n2 > 12000. But I need to use a loop to find the solution and I'm just not quite sure how to code this. Could someone please help me? Thanks in advance
try:

1
2
int n = 0;
while (n^2  <= 12000) n++;


Of course this is CPU intensive, a better option might be

int n = int(sqrt(12000) + 1);

but then there's no loop...
Last edited on
Hi costaaa, may I know your n^2 is referring to n to the power of 2 ?
Just a note that the caret, '^', does not do exponentiation but rather bitwise exclusive or. If you want to do exponentiation, use the pow function in the math library. Or, in the case of n to the power of 2, simply n*n.
Yeah, and ausairman's ^ is referring to the xor operator, which is what ^ is in c++.
Oh yes sorry guys, I do mean n to the power of 2 or n*n
Topic archived. No new replies allowed.