Thread: perfect squares?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    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.

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141

    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);
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    3
    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  2. Small program, PRIME/ PERFECT SQUAREs
    By thynksheraze in forum C++ Programming
    Replies: 6
    Last Post: 01-15-2003, 09:54 AM
  3. Perfect Number Problem
    By TrazPFloyd in forum C++ Programming
    Replies: 21
    Last Post: 10-20-2002, 11:09 AM
  4. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM
  5. Perfect number
    By TheSki in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2001, 04:34 PM