Question: Write a C++ function, sumOfPerfectSquares , that: Takes one parameter, n , a integer. If n is negative , the function should return -1. If

Write a C++ function, sumOfPerfectSquares, that:

Takes one parameter, n, a integer.

If n is negative, the function should return -1.

If n is 0, the function should return 0.

If n is positive, the function should use a loop to calculate and return the sum of all perfect squares from zero to n. For example, with n having a value of 5, the function should return 5 (that is, 1 + 4). Or, with n having a value of 9, the function should return 14 (that is, 1 + 4 + 9).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!