Question

In: Computer Science

Envision an algorithm that when given any positive integer n, it will print out the sum...

Envision an algorithm that when given any positive integer n, it will print out the sum of the squares from 1 to n.

E.g. given 4 the algorithm would print 30 (because 1 + 4 + 9 + 16 = 30) You can use multiplication denoted as * in your solution and you do not have to define it (e.g. 2*2=4)

Write pseudocode for this algorithm using iteration (looping).

Create a flow chart

Implement solution from flowchart in Python at http://www.codeskulptor.org/

Solutions

Expert Solution

Here is the completed solution for this problem. Flowchart, Pseudo code and Python code are attached. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation) in Python code, just copy the code part and paste it in your compiler/IDE directly, no modifications required.

FLOWCHART

PSEUDOCODE

INPUT Variable n

SET sum to 0

SET i to 1

WHILE i<=n DO

                sum=sum+(i*i)

                i=i+1

ENDWHILE

DISPLAY sum     

CODE IN PYTHON

#reading n as integer
n=int(input("Enter the value for n: "))
#initializing sum to 0
sum=0
#looping from 1 to n
for i in range(1,n+1):
    #adding i*i to sum
   
sum+=i*i
#printing sum
print(sum)


Related Solutions

1. Write pseudocode for the algorithm using iteration (looping). Envision an algorithm that when given any...
1. Write pseudocode for the algorithm using iteration (looping). Envision an algorithm that when given any positive integer n, it will print out the sum of the squares from 1 to n. For example given 3 the algorithm will print 14 (because 1 + 4 + 9 =14) You can use multiplication denoted as * in your solution and you do not have to define it (For example. 3*3=9) For example if n is 6 it will print: The sum...
Statement: For a given integer N, print all the squares of positive integers where the square...
Statement: For a given integer N, print all the squares of positive integers where the square is less than or equal to N, in ascending order. Programming Tasks: Prompt the user to input the value of N Output to the screen all squares of positive integers <= N Tests: Item Test 1 Test 2 Test 3 Inputs: 50 9 100 Outputs: 1 4 9 16 25 36 49 1 4 9 1 4 9 16 25 36 49 64 81...
Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You...
Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You write a sequence of numbers, one after another. Start by writing n. If n is even, then the next number is n/2. If n is odd, then the next number is 3n + 1. Continue in this way until you write the number 1. For example, if you start at 7, then the next number is 22 (3 × 7 + 1). The next...
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . ,...
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . , an which are known to be bounded by n 2 (so ai ≤ n 2 , for every i = 1, . . . , n. Use the idea of Radix Sort (discussed in class and presented in Section 8.3 in the textbook). Illustrate your algorithm by showing on paper similar to Fig. 8.3, page 198 in the textbook (make sure you indicate clearly...
Prove that τ(n) < 2 n for any positive integer n. This is a question in...
Prove that τ(n) < 2 n for any positive integer n. This is a question in Number theory
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns,...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns, as output, the sum of the first n positive odd integers. Your solution should be recursive, and it should not contain any "for" loops or "while" loops.
in java please: Given any integer, print an English phrase that describes the integer (e.g. “One...
in java please: Given any integer, print an English phrase that describes the integer (e.g. “One Thousand, Two Hundred Thirty Four”). An ArrayList must be used in your program.
Create a program that will calculate the factorial of any user entered integer. For any positive integer, the factorial is given as
Create a program that will calculate the factorial of any user entered integer. For any positive integer, the factorial is given as: n! = n·(n-1)·(n-2)·.……·3·2·1. The factorial of 0 is 1. If a number is negative, factorial does not exist and this program should display error message. Sample output dialogues should look like these:  Enter an integer: -5 ERROR!!! Tactorial of a negative number doesn't exist  Enter an integer: 10  Factorial = 3628800
Use induction to prove that for any positive integer n, 8^n - 3^n is a multiple...
Use induction to prove that for any positive integer n, 8^n - 3^n is a multiple of 5.
For each given integer n, determine if n is a sum of two squares. (You do...
For each given integer n, determine if n is a sum of two squares. (You do not have to find the squares.) (a) n = 19 (b) n = 45 (c) n = 99 (d) n = 999 (e) n = 1000
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT