Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert the following problem into an algorithm and write it below. remember to

ID: 3882686 • Letter: C

Question

Convert the following problem into an algorithm and write it below. remember to provide an algorithm header, number the algorithm steps and to use pseudocode conventions.

Scan the input array A, counting the number of negative, zero and positive numbers. Let these counts be x, y and z respectively.

                  Create a new array B of the same size and set a local variable neg to 1, zero to x+1, and pos to x+y+1.

                  Scan the input array from left to right, and if the current number being looked at is negative, copy it to B[neg] and increment neg, if it is a zero, copy it to B[zero] and increment zero, and if it is positive, copy it to B[pos] and increment pos.

                  Output array B.

Explanation / Answer

Step1:start

Step2:read the input array A ,which contains the following variables

I)to count

X=no of negatives

Y=no of zeros

Z=no of positives

Step3:create a new array B[]

I)creating variables

Neg: negto1

zero=zerotox+1

Pos=x+y+1

Step 4: read the array B[] from left to right

Step5:if current number is negative the

B[neg]=neg,

Neg++;

Ii)if current number is zero

B[zero]=zero;

Zero++;

Iii)if current number is positive then

B[pos]=pos;

Pos++;

Step6: printing or output arrayB[]

Step7:stop