Question

In: Computer Science

1. Perform a Desk check for the following pseudocode algorithm L1: Program AddFirst5Numbers; L2: Data Counter...

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

Solutions

Expert Solution

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


Related Solutions

1. Write a Racket function (set-equal? L1 L2) that tests whether L1 and L2 are equal....
1. Write a Racket function (set-equal? L1 L2) that tests whether L1 and L2 are equal. Two sets are equal if they contain exactly the same members, ignoring ordering (or in other words, two sets are equal if they are a subset of each other). For example (set-equal? '(1 (2 3)) '((3 2) 1)) ---> #t (set-equal? '(1 2 3) '((3 2)1)) ---> #f (set-equal? '(1 2 3) '((1 2 3))) ---> #f 2. Two common operations on sets are...
Problem 1: (10 marks) ALGORITHM COMPLEXITY:Write an algorithm (pseudocode but not a program) that takes a...
Problem 1: ALGORITHM COMPLEXITY:Write an algorithm (pseudocode but not a program) that takes a positive numberias an input, where i=a1a2...an,n>=3(numberwith 3 or more digits, every digit can have the value between 0 and 9–both inclusive). The algorithm should find the largest number jsuch that j=b1..bm, 1<=m<=n(numberwith m digits),andevery bk<=bk+1where1<=k<m and bk,bk+1ε{a1, a2, an}.Also, perform the computational complexity (time complexity)analysis of your algorithm and write the algorithm complexity in Big-Oh notation. Examples:Input: 23720, Output: 237Input: 9871, Output: 9Input: 1789, Output:1789Input: 2372891,...
1) Equations for two lines L1 and L2 are given. Find the angle between L1 and...
1) Equations for two lines L1 and L2 are given. Find the angle between L1 and L2. L1: ? = 7 + 2?, ? = 8 − 4?, ? = −9 + ? L2: ? = −8 − ?, ? = 3 − 3?, ? = 4 + 3? 2) Find polar form of complex number z : ?) ? = 4√3 − 4? ?) ? = 2√3 − 2i
. Observation data for the three L1, L2 and L3 locations are presented in the table...
. Observation data for the three L1, L2 and L3 locations are presented in the table as below L1 L2 L3 5 3 6 7 2 8 7 5 6 13 11 9 10 using α = 5%, test whether the conditions at the three locations are the same?
Show your results all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application...
Show your results all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application that allows a user to enter the price of an item and computes 6.25 percent sales tax on the item.
Show your results using all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an...
Show your results using all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application that allows a user to enter the number of text messages he or she sent last month and then displays the bill. Messages cost 25 cents each, and 8 percent tax is charged on the total.
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ......
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ... n - 1]) if (n = 2) and A[0] > A[1] swap A[0] and A[1] else if n > 2 m = ceiling(2n/3) STOOGESORT(A[0 ... m - 1]) STOOGESORT(A[n - m ... n - 1]) STOOGESORT(A[0 ... m - 1])
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the following requirements: Reads in a series of positive integers,  one number at a time;  and Calculate the product (multiplication) of all the integers less than 25,  and Calculate the sum (addition) of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]...
Consider the following pseudocode for insertion-sort algorithm. The algorithm sorts an arbitrary array A[0..n − 1]...
Consider the following pseudocode for insertion-sort algorithm. The algorithm sorts an arbitrary array A[0..n − 1] of n elements. void ISORT (dtype A[ ], int n) { int i, j; for i = 1 to n – 1 {     //Insert A[i] into the sorted part A[0..i – 1]     j = i;     while (j > 0 and A[j] < A[j – 1]) {         SWAP (A[j], A[j – 1]);         j = j – 1 }     }...
Exercise 1. Write an algorithm (pseudocode) to read a set of sales data items from standard...
Exercise 1. Write an algorithm (pseudocode) to read a set of sales data items from standard input and calculate and output their total and their average. Prompt user to enter number of data items. Exercise 2. Create a test data set to verify your algorithm. How many cases are needed? Explain. Write your test data set below for submission to the EOL dropbox upon completion of your lab. Number of items List data items Expected output Case 1: Exercise 3....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT