I'm doing a sieve of eratosthenes problem and I'd like to loop to sqrt(number). Is it possible to do this in the loop with the sqrt() function provided by math.h? I'd ideally like to be able to not have to make another variable in my function and instead just do it in the loop like this:
for (__int64 x=0; x<sqrt(num)); x++)
The problem is that x is an integer (doesn't matter if it's 32 bit) and sqrt returns a double. Do I need to cast it to something different? Hints appreciated.
You don't want to call sqrt() directly in your for loop because then the sqrt can be calculated every single time the loop iterates (which is wasteful). It's better to calculate the sqrt ahead of time and stuff it in a var, then use the var in the loop.