Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The objective is to use each row of the first column as a starting point to come up with a sum of absolute value of

The objective is to use each row of the first column as a starting point to come up with a sum of absolute value of differences . For each row, a sum will be calculated, therefore, 5 sums must be calculated. Each sum will be placed into the array, sumList[ ].

#include #include #include #define ROWS 5 #define COLS 6 void calcSums(int topog[ROWS][COLS], int sumList[ROWS] ); int main() { int topography[ROWS][COLS] = { { 3011, 2800, 2852, 2808, 2791, 2818 }, { 2972, 2937, 2886, 2860, 2830, 2748 }, { 2937, 2959, 2913, 2864, 2791, 2742 }, { 2999, 2888, 2986, 2910, 2821, 2754 }, { 2909, 3816, 2893, 2997, 2962, 2798 } }; int sumList[ROWS] = {0}; int r,c; /* student to implement calcSums */ calcSums(topography, sumList ); //pass in topography, get back list of elevation sums

for(r=0; r < ROWS; r++) printf("%8d %8d ",r, sumList[r]); //should display

return 0; } /* * Receives 2d matrix that represents topography * and uses this data to calculate an elevation path sum for each * row. * Input: topog[][] * Output: sum[] * */ void calcSums(int topog[ROWS][COLS], int sums[ROWS] ) { int i,j; for( i=0; i

int sum= abs(topog[i][j])- abs(topog[i][j+1]); int sum2 = abs(topog[i+1][j])- abs(topog[i][j+1]); int sum3 = abs(topog[i-1][j])- abs(topog[i][j+1]); if (sum < sum2&& sum< sums3){ sums[i] = sum; } if (sum2 < sum1 && sum2< sums3){ sums[i] = sum; } if (sum3 < sum1&& sum3< sums2){ sums[i] = sum; } sums [i] = topog

}}

sums[i] = 99999; //place sums in this array. One sum per row

}

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

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions