Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

Which form of proof do you find most persuasive? Why?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago