Question: Create a method called sumOfPows. It should take three integers, a, b and c, as arguments and return the sum of each of the values
Create a method called sumOfPows. It should take three integers, a, b and c, as arguments and return the sum of each of the values between a and b inclusive raised to the power of c. You may not make any assumptions as to whether a or b will be larger.
Examples:
sumOfPows(1, 5, 2) results in 55 because 12 + 22 + 32 + 42+ 52= 55
sumOfPows(3, -3, 3) results in 0 because 33 + 23 + 13+ 03+ (-1)3 + (-2)3 + (-3)3 = 0
You must use a for loop to solve this problem. Other approaches will not receive any credit.
int sumOfPows(int a, int b, int c) {
Step by Step Solution
There are 3 Steps involved in it
Certainly To solve this problem we need to write a method called sumOfPows The function should ta... View full answer
Get step-by-step solutions from verified subject matter experts
