Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program so that computes and prints the sum of each column of the array. This problem is harder than the previous because some
Write a program so that computes and prints the sum of each column of the array.
This problem is harder than the previous because some rows have more columns than others. You can't just reverse the inner and outer loops of the previous program because this will try to access columns that don't exist in some rows. One solution is to create a second D array that holds the column sums. Make a first pass over the data array to determine how long this array of sums should be Iterate over the array as before adding each array element to the appropriate sum as it is encountered.
TURN IN:
Solve this problem without using a second array the logic might be tricky, unless you think in through.
For this assignment, do not use a nd array eg solve in place'
Note: You will still need a first pass over the array.
Use the following Array for testing:
int data
;
NOTES:
Don't let the title scare you :
This problem has 'ragged' D arrays different lengths of each row
You must check each row's array length and ensure you do not allow indices to stray out of bounds!
If a corresponding array value in a column does not exist, mathematically it is zero, or 'skip' the additions depending on how you choose to solve the problem
The program must work for any array input, eg I may use an alternative D array to see how your program handles it
The AP exam in May will not require use of ragged arrays in FRQ nor give such MCQ problems.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started