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

Write a program that creates a 5 by 5, two-dimensional array that store 25 integ

ID: 3813072 • Letter: W

Question

Write a program that creates a 5 by 5, two-dimensional array that store 25 integers and the program will call five functions.

• Function display(): the program will display all the integers (in the 5 by 5 format)
• Function calculateTotal(): the program will return the total of the 25 integers
• Function totalRow(): returns and displays a 5-element array with each of the element showing the total of all the elements of the same row in the 5 by 5 array.
• Function totalColumn(): returns and displays a 5-element array with each of the element showing the total of all the elements of the same column in the 5 by 5 array
• Function maximum(): returns the largest value in the 5 by 5 array

Explanation / Answer

Hi,

Here is the code in C-

#include <stdio.h>
const int M = 3;
const int N = 3;
void print(int arr[M][N])
{
int i, j;
for (i = 0; i < M; i++)
for (j = 0; j < N; j++)
printf("%d ", arr[i][j]);
}
void print_RowSum(int arr[M][N])
{int sum=0;
int i,j;

for (i = 0; i < M; ++i)
{
for (j = 0; j < N; ++j)
{
sum = sum + arr[i][j] ;
}
printf("Sum of the %d row is = %d ", i, sum);
sum = 0;
}
}
void print_ColSum(int arr[M][N])
{ int i,j;
int sum = 0;
for (j = 0; j < M; ++j)
{
for (i = 0; i < N; ++i)
{
sum = sum + arr[i][j];
}
printf("Sum of the %d column is = %d ", j, sum);
sum = 0;
}
}
void calculateTotal(int arr[M][N])
{ int i,j;
int sum = 0;
for (j = 0; j < M; ++j)
{
for (i = 0; i < N; ++i)
{
sum = sum + arr[i][j];
}
  
  
}
printf("Sum of all the values is = %d ", sum);
}
void findMaxn(int arr[M][N])
{
int max=arr[0][0];
int i,j;

for (i=0; i<M; i++)
for (j=0; j<N; j++)
{   
if(arr[i][j]> max)
max= arr[i][j];
  
}
printf("Maximum value is %d ", max);
}
int main()
{
int arr[M][N] ;
int p,q;
printf("Enter the number for the array");
for (p = 0; p < M; p++)
for (q = 0; q < N; q++)
scanf("%d",&arr[p][q]);
print(arr);
print_RowSum(arr);
print_ColSum(arr);
findMaxn(arr);
calculateTotal(arr);
return 0;
}

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