In: Computer Science
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/
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)