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

in c++ console Write a program that creates a 5 by 5, two-dimensional array that

ID: 3804825 • Letter: I

Question

in c++ console

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

here i have make the 5 function which is performing the following task:-

• display(): displaying all the integers
• calculateTotal(): returning the total of the 25 integers
• totalRow():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.
• totalColumn(): 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
• maximum(): returning the largest value in the 5 by 5 array

#include <iostream>

using namespace std;

void display(int a[][5])
{
   for(int x=0;x<5;x++)
   {
       for(int y=0;y<5;y++)
        {
        cout<<a[x][y]<<" ";
        }
        cout<<endl;
   }
}

int calculateTotal(int a[][5])
{
   int sum=0;
   for(int x=0;x<5;x++)
{
for(int y=0;y<5;y++)
{
sum=sum+a[x][y];
}
}
return sum;
  
}

void totalRow(int a[][5])
{
   int sum=0;
   for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
{
sum = sum + a[x][y] ;
}
cout<<"Sum of the "<<x <<" row is ="<< sum<<endl;
  
sum = 0;
}
cout<<endl;

}

void totalColumn(int a[][5])
{
   int sum=0;
   for (int y = 0; y < 5; y++)
{
for (int x = 0; x < 5; x++)
{
sum = sum + a[x][y] ;
}
cout<<"Sum of the "<<y <<" column is ="<< sum<<endl;
  
sum = 0;
}
cout<<endl;

}

int maximum(int a[][5])
{
   int maxElement;
   maxElement = a[0][0];
  
   for(int x = 0 ; x < 5 ; x++ )
   {
   for(int y = 0 ; y < 5 ; y++ )
   {
   if ( a[x][y] > maxElement )
   maxElement = a[x][y];
   }
    }
    return maxElement;
}

int main()
{
   int matrix[5][5];
   cout<< "enter the 5*5 array number:- "<<endl;

for(int x=0;x<5;x++)
{
for(int y=0;y<5;y++)
{
cin>>matrix[x][y];
}
}
display(matrix);
  
cout<<"sum of matrix elements :- "<<calculateTotal(matrix)<<endl<<endl;
  
totalRow(matrix);

totalColumn(matrix);
  
   cout<<"maximum element of 5*5 is :- "<<maximum(matrix)<<endl;


return 0;
}