In: Computer Science
1. Perform a Desk check for the following pseudocode algorithm
L1: Program AddFirst5Numbers;
L2: Data Counter as Integer;
L3: Data Sum as Integer;
L4: Counter:= 1;
L5: Loop until Counter = 5
L6: Sum := Sum + Counter;
L7: counter := counter + 1;
L8: Next Loop;
L9: Output “The sum is”, Sum;
L9: End AddFirst5Numbers;
2. Write a pseudocode algorithm to print the following pattern
2 4 6 8 10
3. Using nested loops, write a pseudocode algorithm to print the following pattern
64 56 48 40 32
64 56 48 40
64 56 48
64 56
48
hello,
1) On performing the desk checking of first question, it shows that the value of variable 'Sum' is not initialized to zero which will lead to error in Line L6 since you are adding a value 'counter' to 'Sum' and 'Sum' has no defined value.
So i suggest you to add an extra statement given below, add it just after statement " Counter:= 1; "
Sum=0
2) Pseudocode for the pattern 2 4 6 8 10 is given below:-
Start Program
counter=1
loop until counter=5
Output (2*counter)
counter=counter+1
Next Loop
End Program
3) Pseudo Code for the pattern will be
Start Program
counter =5
loop until counter = 1
inner_counter=1
loop until inner_counter=counter
Output(72-(inner_counter*8))
inner_counter=inner_counter+1
Next Loop;
Next Line;
counter=counter-1
Next Loop;
End Program
I hope i was able to solve your problem to a greater extent, feel free to comment your queries i will surely respond to them. Please consider my efforts and please upvote my solution
Thanku