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

Complete the C function describe below. Some marks will be given for the quality

ID: 3575673 • Letter: C

Question

Complete the C function describe below. Some marks will be given for the quality of your code (i.e., dealing with possible error conditions). List all assumptions; note that unreasonable assumptions will be penalized. (Note that the input parameter must not be modified by your solution.)/* * shrink_array * * input: * -- int *a: an existing array of integers, where the last element is indicated by a negative value. The contents of this array must not be overwritten. * * purpose: each positive, non-zero value in a[] is copied into b[]. * the new array is returned. * * example: if a[] = {3, 0, 4, 0, 5, 31, -1} then the value returned * by shrink_array is some integer array of the value {3, 4, 5, 31, -1} */int *shrink_array(int *a)

Explanation / Answer

b[] should be declared globally

int *shrink_array(int *a)
{
   int i,j=0,k;
   for(i=0;i<7;i++)
   {
       if(*a==0)
       {
       *a++;     //incremented the array position if 0
       }
       else         // else copied into the second array
       {
       b[j++]=*a;
       *a++;
       }
   }
   for(k=0;k<j;k++)
   printf("%d ",b[k]);
   return NULL;
}

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