php homework question, calculate sum of squares?

lulu

New member
I don't need help with the code, but with the logic behind it. This is the question:
Write a program that accepts an integer larger than 1 and calculates the sum of the squares from 1 to that integer. For example, if the integer equals 4, the sum of the squares is 30 (1 + 4 + 9 + 16, notice 4 numbers)

Things to keep in mind..

I'm not getting user input, I'll just create a variable and manually assign the value of the integer.
I think the best way is a while loop, defining a variable for the integer, one for the square operation and incrementing the integer (or decrementing?) to get to all the numbers' squares before that integer, and a sum variable that I will echo out including a (constant for 1?) + squares of numbers in between + the actual integer's square

Any thoughts?

I'm new at this and I have no idea about libraries yet. It's plain math that I can't figure out.

Like I said, I'm not looking for code but just the logic :)

Thanks!
 
Back
Top