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

Please write program using basic C, thanks! (20 points): Write a Program to find

ID: 3597394 • Letter: P

Question

Please write program using basic C, thanks!

(20 points): Write a Program to find the sum, average, minimum and maximum of all elements of each row of a matrix. The user first enters the number of rows and columns, then enters all of the data of the matrix. Then the program will print the matrix elements and the sum, the average, the minimum, and the maximum of each row. The output should be as below: (Submit a repl link.) Enter number of Rows: 2 Enter number of cols :2 Enter matrix elements: Enter element [1,1]:1 Enter element [1,2] 2 Enter element [2,1] 3 Enter element [2,2] 1 SUM: 3 SUM4 Average 1.50 maximum2, mininum 1 Average 2.00 maximum3, mininum 1

Explanation / Answer


#include <stdio.h>

#include <stdio.h>

int main()
{
int m, n, c, d, first[10][10],i,min,max,total;
int arr[10];
float average;

printf("Enter the number of rows in matrix ");
scanf("%d", &m);
printf("Enter the number of columns in matrix ");
scanf("%d", &n);
printf("Enter the elements of matrix ");

for (c = 0; c < m; c++){
for (d = 0; d < n; d++){
  
printf("Enter element [%d,%d]: ",c+1,d+1);

scanf("%d", &first[c][d]);
}
}


for (c = 0; c < m; c++) {
for (d = 0 ; d < n; d++) {
total+=first[c][d];
printf("%d ", first[c][d]);
arr[d]=first[c][d];

}
printf("Sum %d ", total);
average=(float)total/n;

printf("Average %f ", average);
total=0.0;   

/* Assume first element as maximum and minimum */
max = arr[0];
min = arr[0];


for(i=1; i<n; i++)
{
/* If current element of array is greater than max */
if(arr[i]>max)
{
max = arr[i];
}

/* If current element of array is smaller than min */
if(arr[i]<min)
{
min = arr[i];
}
}

/* Print maximum and minimum element */
printf("Maximum = %d, ", max);
printf("Minimum = %d", min);

printf(" ");
}

return 0;
}

output

Enter the number of rows in matrix
2   
Enter the number of columns in matrix   
2   
Enter the elements of matrix
Enter element [1,1]: 1
Enter element [1,2]: 2
Enter element [2,1]: 3
Enter element [2,2]: 1
1 2 Sum 3 Average 1.500000 Maximum = 2, Minimum = 1   
3 1 Sum 4 Average 2.000000 Maximum = 3, Minimum = 1