-
perfect squares?
Part of my assignment is to find "magic squares". That is, perfect squares that are the sum of consecutive intergers. I get the second part, but I have no idea how to check that the square root of the sum of consecutive numbers is an interger (and therefor a perfect square). Maybe I need to find another way to check for perfect squares?
any ideas would be appreciated.
-
answer
Maybe I am misreading, but any odd number is the sum of consequctive integers, correct?
As for checking if the squareroot is an integer, try
bool squareRootIsInt(double arg) {
return sqrt(arg) == (int) sqrt(arg);
}
-
the sum of consecutive ints would be 1, 1+2=3, 1+2+3=6, 1+2+3+4=10, and so on in my problem. Not just 2+3 or 3+4, or something like that. Your probably not misreading, it's more likely I didn't explain it properly.
Anyway, I ended up comparing the square root to the floor of the square root. It seems to work. Thanks all the same!