View the step-by-step solution to:

Question

I need help to write a C function that takes a 4x4 two-dimensional array of floating point numbers matrix as a

parameter. The function computes the average of the first three elements of each row of the array and stores it at the last element of the row.

The function prototype is given as follows:

void findAverage2D(float matrix[4][4]);


A sample program template is given below to test the function:

#include <stdio.h>

void findAverage2D(float matrix[4][4]);

int main()


 7

 float ar[4][4];

 int i,j;


 printf("Enter data: n");

 for (i = 0; i < 4; i++) {

 for (j = 0; j < 4; j++)

 scanf("%f", &ar[i][j]);

 }

 findAverage2D(ar);

 printf("findAverage2D(): :n");

 for (i = 0; i < 4; i++) {

 for (j = 0; j < 4; j++)

 printf("%.2f ", ar[i][j]);

 printf("n");

 }

 return 0;

}

void findAverage2D(float matrix[4][4])

{

 /* Input your code here */

}


Some sample input and output sessions are given below:


(1) Test Case 1:

Enter data:

1 2 3 0

4 5 6 0

7 8 9 0

1 2 3 0

findAverage2D():

1.00 2.00 3.00 2.00

4.00 5.00 6.00 5.00

7.00 8.00 9.00 8.00

1.00 2.00 3.00 2.00


(2) Test Case 2:

Enter data:

1 2 3 0

4 5 6 0

-4 -5 -6 0

1 2 3 0

findAverage2D():

1.00 2.00 3.00 2.00

4.00 5.00 6.00 5.00

-4.00 -5.00 -6.00 -5.00

1.00 2.00 3.00 2.00


(3) Test Case 3:

Enter data:

1.5 2 2.5 0

4 5 6 0

-4 -5 -6 0

1 2 3 0

findAverage2D():

1.50 2.00 2.50 2.00

4.00 5.00 6.00 5.00

-4.00 -5.00 -6.00 -5.00

1.00 2.00 3.00 2.00


Would you be able to do a brief description for each line of code. Thanks

Top Answer

#include &lt;stdio.h&gt; void findAverage2D ( float matrix[ 4 ][ 4 ]) ; int main () { float ar[ 4 ][ 4 ]; int i,j; ... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question