- #1
Niaboc67
- 249
- 3
I am trying to understand pseudo-code and an assignment that was given and which I have the answer to.
Question:
Write pseudo code for a program that computes the sum of the even numbers from use-provided values. The program will first read the number of values (N) that the user will input. It will then process the N values from user input, one by one. Finally, it will print the sum.
To keep things simple, you can read the next integer and store it in some variable x as follows: x=read
you can print a value x or message as follows: print(x) or print("hello")
-------------------------------------------------------------------------------------------------------------------------------------------------
The answer:
-------------------------------------------------------------------------------------------------------------------------------------------------
I do not understand this. If someone could please explain step-by-step the meaning here it would be greatly appreciated. What does each line represent? why is it there?
Question:
Write pseudo code for a program that computes the sum of the even numbers from use-provided values. The program will first read the number of values (N) that the user will input. It will then process the N values from user input, one by one. Finally, it will print the sum.
To keep things simple, you can read the next integer and store it in some variable x as follows: x=read
you can print a value x or message as follows: print(x) or print("hello")
-------------------------------------------------------------------------------------------------------------------------------------------------
The answer:
Code:
START
N = READ
SET I = 0
SET SUM = 0
WHILE I < N
X = READ
IF N%2 IS 0 : SUM = SUM + X
I = I+1
ENDWHILE
PRINT(SUM)
EXIT
I do not understand this. If someone could please explain step-by-step the meaning here it would be greatly appreciated. What does each line represent? why is it there?