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

Download h3-2.s from the course website. Read Appendix A which discusses how loc

ID: 3861026 • Letter: D

Question

Download h3-2.s from the course website. Read Appendix A which discusses how local array variables are allocated in the stack frame of a function and how an array is passed as an argument in a function call. Let array be a 1-dimensional array of ints. The size of array, i.e., the number of elements in array, is specified by variable n. Shown below is the pseudocode for a function count () which has array and n as parameters. This function walks through array counting the number of negative values and the number of non-negative values in the array. It returns both counts. function count (array: int[], n: int) rightarrow int, int int i, neg, nonneg for i leftarrow 0 to n - 1 do if arrayi

Explanation / Answer

6)

a)

i=0

while(i!=n-1) // This while loop will keep incrementing until value of i becomes n-1, just like for loop in the problem statement.

{

if (array[i]<0)

neg+=1;

else

nonneg+=1;

i+=1;

}

b)

i=0;

if (i==n-1)

goto jump; // Goto always needs a label so label for this is defined outsode the block given below because if the //condition i== n-1 is true the control will goto jump, otherwise in the block the value of i will keep on incrementing //until it becomes n-1

{

i+=1;

if (array[i]<0)

neg+=1;

else

nonneg+=1;

i+=1;

}

jump:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote