Sum of squares
Inputs
n is a whole number from 0 to 30.
Your tasks
- Create a number
totalthat starts at 0. - Use a loop over the whole numbers 1 up to and including
n. Add each number multiplied by itself tototal. - Complete
sumOfSquaresso it returnstotal. Return it, do not print it.
Example
With n = 4, sumOfSquares returns 30.
Rules
- If
nis 0, return 0.
Test data
TEST DATA 1: n is 4
TEST DATA 2: n is 0
Practice focus
Loops that count, add up and multiply. Every algorithm starts here: a counter, a total and a stopping point.