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
Get step-by-step solutions from verified subject matter experts
