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

This program is an exercise in working with two-dimensional arrays and pointers-

ID: 3562633 • Letter: T

Question

This program is an exercise in working with two-dimensional arrays and
pointers-to-pointers. A two-dimensional array of ints is allocated from the
stack and initialized in "main". This is passed to FindMaxArray, along with
the address of a local pointer-to-an-int. After the function returns, the
local int pointer should be pointing to the array with the largest sum.

Output:
Here is the array with the maximum sum:
22 + 500 + -67 + 1 = 456

Please help me debug my code, This is an array with 2 dimensions (5x4). Cap values are constant that listed before main. I need to calculate the sum of each sub array and find the array has the biggest sum and return their items on the screen.

This is my code, CalArraySum function will calculate the sum of each one dimention sub array, FindMaxArray function will determine which is the array with largest sum and set a pointer to it.

DispArray receive the pointer, and display the contents of the biggest array. Some how i keep getting error about my pointer in the FindMaxArray function.

Do not fix anything in main.

Please help me and explain. Thank you!

Explanation / Answer

In FindMaxArray, take out this statement sum=sum+CalcArraySum(matrix[i],4); and Instead of if(sum>max) try with

If(max> CalcArraySum(matrix[i],4))

              Max= CalcArraySum(matrix[i],4);

Finding in your code: Function CalcArraySum is already calculating the subarray sum so you can compare with max and assign accordingly in FindMaxArray . I hope that is missing in your code.

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