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

The following problems involve the use of pointers to traverse and process the e

ID: 3815665 • Letter: T

Question

The following problems involve the use of pointers to traverse and process the elements of an array. Create one program for all problems. Save the program and turn it in on Blackboard/Learn under the EC6 Pointers assignment. This assignment is worth a possible total of 5 extra credit points on the Final Exam. Create an array A with four rows and six columns. Initialize the array to random integer values from 17 to 72. Use POINTERS with an offset to perform the following operations on this array. Doing these exercises with subscripts will not gain you any extra credit points! Print the array in a table form Find the sum of the second row of values Find the sum of the third column of values Find the max in the first three rows of values Find the min in the last four columns of value

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>                    //For the rand() function

int main(void)
{
   int A[4][6];
   int i, j;                            //Row and column traversers

   for(i=0; i<4; i++)
   {
       for(j=0; j<6; j++)
       {
           *(*(A+i)+j) = rand()%56 + 17;
       }
   }


   //Printing in Table form
   for(i=0; i<4; i++)
   {
       for(j=0; j<6; j++)
       {
           printf("%d ", *(*(A+i)+j));
       }
       printf(" ");
   }


   //Sum of the second row values
   int sum = 0;
   for(j=0; j<6; j++)
   {
       sum = sum + *(*(A+1)+j);
   }
   printf(" The sum of the second row values: %d ", sum);


   //Sum of the third column values
   int sum2 = 0;
   for(i=0; i<4; i++)
   {
       sum2 = sum2 + *(*(A+i)+2);
   }
   printf(" The sum of the third column values: %d ", sum2);  


   //Max of the first three row values
   int max = 0;
   for(i=0; i<3; i++)
   {
       for(j=0; j<6; j++)
       {
           if( max < *(*(A+i)+j) )
               max = *(*(A+i)+j);
       }
   }
   printf(" The max of the first three row values: %d ", max);


   //Min of the last four column values
   int min = 99;
   for(i=0; i<4; i++)
   {
       for(j=2; j<6; j++)
       {
           if( min > *(*(A+i)+j) )
               min = *(*(A+i)+j);
       }
   }
   printf(" The min of the last four column values: %d ", min);
}