Answer to Question #318556 in Algorithms for beki

Question #318556

Solve the following problem by showing the design of your solution as an algorithm.


The problem – The program will take two integers from the user, say n1 and n2. It will then print the sum of all numbers between n1 and n2, inclusive. For example, if the user enters 5 and 9, the program will print the value of 5+6+7+8+9. On the other hand, if the user enters 5 and -2, the program will print the value of 5+4+3+2+1+0+(-1)+(-2). Note: Do not assume the user will always enter the smaller number first.

1
Expert's answer
2022-03-26T05:45:45-0400

1 Read n1

2 Read n2

3 If n1 < n2

4 Set step equal 1

5 Else

6 Set step equal -1

7 Set sum equal 0

8 Set i equal n1

9 If i equal n2 go to step 13

10 Add i to sum

11 Add step to i

12 Go to step 9

13 Print sum



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS