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

Write a complete program that will have a main function and a function called av

ID: 3778478 • Letter: W

Question

Write a complete program that will have a main function and a function called average. (Ret: slides 68 and 69 of lecW9_arrays, slides 47 to 49 of lec W6 fune) a. Function average will only have a 2D integer array parameter with 2 rows and 3 columns. This function will return the average of the elements stored in 2D array. Use nested counter-controlled for loop. (Use array template instead of built-in array) h. In main(). declare a 2D integer array template called t with 2 rows and 3 columns, c. In main(). initialize the array using initializer list such that: First row will have values 1, 2, 3 (from left to right) Second row will have values 6, 8, 0 (from left to right) d. Call the function average from main such that it will return the average of the elements stored in array e. In main(), store the value returned from the function average in a variable. Then. print that variable.

Explanation / Answer

The below is the code for the above problem in C language.

#include <stdio.h>

int average(int t[2][3]){
int i,j;
int average,sum=0;
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
sum = sum+ t[i][j];
}
}
average = sum/2*3;
return average;
}

int main()
{
int Avg;
int t[2][3] = {{1, 2, 3}, {6, 8, 0}};
Avg = average(t);
printf("Average of the Elements: %d ",Avg);
return 0;
}

output is 30.

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