Question
The sum of squares of n is n2 + (n-1)2 + (n-2)2 + ... + 12 for n>=1. Write code that uses a for loop
The sum of squares of n is n2 + (n-1)2 + (n-2)2 + ... + 12 for n>=1.
Write code that uses a for loop (not a while or do loop) that starts the loop counter i at n, and reduces i by 1, as long as i is >= 1, and inside the loop we accumulate i2. After the loop is done, return the accumulated value.
Now place this code inside a function named squaresOf, which takes one parameter n as integer, and returns an integer. Declare all other needed variables.
Note that you must write the function definition and name and use the variables (and their names) above exactly as noted. You may add other variables as needed.
Do not add any other code here.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started