Answered step by step
Verified Expert Solution
Link Copied!

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 1D 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 2nd array (e.g., solve 'in place').
Note: You will still need a first pass over the array.
Use the following Array for testing:
int [][] data ={{12,24,48,96,128},
{-4,34,22,-10,-256,12},
{14,-64,-88,144},
{16},
{32,64,128,-256}};
NOTES:
1. Don't let the title scare you :).
2. This problem has 'ragged' 1D arrays (different lengths of each row).
3. You must check each row's array length and ensure you do not allow indices to stray out of bounds!
4. 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).
5. The program must work for any array input, e.g., I may use an alternative 2D array to see how your program handles it.
6. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Can workers be trained in ethics? How? Defend your answer.

Answered: 1 week ago