Answer to Question #119082 in Algorithms for Raahim Agha

Question #119082
Draw a flow diagram for an algorithm which calculates how many numbers 1, 2, 3…n have to be added to reach a total greater thah 500. Output the answer n.

1
Expert's answer
2020-05-31T15:59:51-0400

First, write the equation for the sum of the arithmetic progression with difference d=1 and the first element a1=1:


"S=\\frac{n[2a_1+(n-1)d]}{2}=\\frac{n^2+n}{2}."

The sum must be greater than 500:


"\\frac{n^2+n}{2}>500,"

transform the inequality:


"n^2+n-1000>0."


Algorithm:

for int n=1 to infinity:  

if n^2+n-1000<0,

then continue

else print(n)

Draw the flow diagram:


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