Extra Credit: Ch 6 Pointers The following problems involve the use of pointers t
ID: 3768204 • Letter: E
Question
Extra Credit: Ch 6 Pointers
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.
Problems:
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
PLEASE USE THE C PROGRAMMING LANGUAGE FOR THIS EXCERISE
Explanation / Answer
Here is the code for you. If you have any queries, or found any discrepancies, just get back to me.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int A[4][6];
srand(time(NULL));
for(int i = 0; i < 4; i++)
for(int j = 0; j < 6; j++)
A[i][j] = rand() % 56 + 17;
//Print the array in a table form
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 6; j++)
printf("%i ", *((int *)A+i*6+j));
printf(" ");
}
//Find the sum of the second row of values.
int sum = 0;
for(int i = 0; i < 6; i++)
sum += *((int *)A+6+i);
printf("The sum of second row of values is: %i ", sum);
//Find the sum of the third column of values.
sum = 0;
for(int i = 0; i < 4; i++)
sum += *((int *)A+i*6+2);
printf("The sum of the third column of values is: %i ", sum);
//Find the max in the first three rows of values
int max = **A;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 6; j++)
if(*((int *)A+6*i+j) > max)
max = *((int *)A+6*i+j);
printf("The maximum of the first three rows of values is: %i ", max);
//Find the min in the last four columns of value.
int min = **(A+2);
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
{
if(*((int *)A+(6*i+j)+2) < min)
min = *((int *)A+(6*i+j)+2);
}
printf("The minimum of the last four columns of values is: %i ", min);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.