WRITTEN PROBLEMS (8 pts)
Hand these problems in on paper in class on the due date specified.
Give an algorithm made up of instructions of the type shown above to draw the following pictures substituting in appropriate values for x, y, s and r in each instruction.
The result of your last algorithmic step should be the final answer. NOTE: In the second computation, can you figure out how to write only four instructions to generate the answer?
1. Input c. 2. Set d = 0. 3. While c ≠ 0, do the following: a. If c modulo 5 = 0, add c to d. b. Subtract 1 from c. 4. Output d.
1. Set sum equal to __________. 2. Set index equal to __________. 3. While index ____ n, do the following: a. If __________________________, add A[index] to sum. b. Add 1 to index. 4. Output sum.
Hand this in electronically using the Electronic Handin System by 11:59PM on the due date indicated.
Write a short Python program on your computer named computesum.py that computes the sum of the positive integers up to n, where n > 0. For example, if n is 5, then the program should output 15 since 1 + 2 + 3 + 4 + 5 = 15. Use the python interpreter to test your work carefully for correctness.
Here is the general algorithm to follow:
1. Input n 2. Set answer = 0. 3. Set i = 0. 4. While i < n, do the following: a. Add 1 to i. b. Add i to answer. 5. Output answer.
You may assume the input value will always be a positive integer.