Problem

Sum of consecutive integers(a) Write a program that prompts for an integer—let’s call it X...

Sum of consecutive integers

(a) Write a program that prompts for an integer—let’s call it X—and then finds the sum ofX consecutive integers starting at 1. That is, if X = 5, you will find the sum of 1 + 2 + 3 + 4+ 5= 15.

(b) Modify your program by enclosing your loop in another loop so that you can find consecutive sums. For example, if 5 is entered, you will find five sums of consecutive numbers:

1           = 11+ 2        = 31+2+3       = 61+2+3+4     = 101+2+3+4+5   = 15

Print only each sum, not the arithmetic expression.

(c) Modify your program again to only print sums if the sum is divisible by the number of operands. For example, with the sum 1 + 2 + 3 + 4 + 5=15, there are five operands and the sum, 15, is divisble by 5, so that sum will be printed. (Do you notice a pattern?)

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT