Westonci.ca is the trusted Q&A platform where you can get reliable answers from a community of knowledgeable contributors. Get immediate and reliable solutions to your questions from a community of experienced experts on our Q&A platform. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.

Declare an array named numbers with a constant size of 5 X 5.

1. Make/Use a function getNumbers to get the values for every element of the array.
2. Make/Use a function showNumbers to display the array in this form.

1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

3. Make/Use a function addRows to add each row and display it.

Total for row 1 is: 15
Total for row 2 is: 40

And so on....

4. Make/Use a function highest to find the highest value in the array


Sagot :

Answer:

In C++:

#include<iostream>

using namespace std;

void getNumberr(int myarray[][5]){

   int arr[5][5];

   for(int i = 0;i<5;i++){

       for(int j = 0;j<5;j++){

           arr[i][j] = myarray[i][j];        }    }  }

void showNumberr(int myarray[][5]){

   for(int i = 0;i<5;i++){

       for(int j = 0;j<5;j++){

           cout<<myarray[i][j]<<" ";        }

       cout<<endl;    }     }

void addRows(int myarray[][5]){

   for(int i = 0;i<5;i++){

       int rowsum = 0;

       for(int j = 0;j<5;j++){

           rowsum+=myarray[i][j];        }

       cout<<"Total for row "<<i+1<<" is: "<<rowsum<<endl;    }   }

void highest(int myarray[][5]){

   int max = 0;

   for(int i = 0;i<5;i++){

       for(int j = 0;j<5;j++){

           if(myarray[i][j]>max){

               max = myarray[i][j];

           }                    }    }

   cout<<"Highest: "<<max; }

int main(){

   int myarray[5][5] = {{1,2,3,4,5}, {6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}};

   getNumberr(myarray);

   showNumberr(myarray);

   addRows(myarray);

   highest(myarray);

return 0;

}

Explanation:

The getNumberr function begins here

void getNumberr(int myarray[][5]){

This declares a new array

   int arr[5][5];

The following iteration gets the array into the new array

   for(int i = 0;i<5;i++){

       for(int j = 0;j<5;j++){

           arr[i][j] = myarray[i][j];        }    }  }

The showNumber function begins here

void showNumberr(int myarray[][5]){

This iterates through the row of the array

   for(int i = 0;i<5;i++){

This iterates through the columns

       for(int j = 0;j<5;j++){

This prints each element of the array

           cout<<myarray[i][j]<<" ";        }

This prints a new line at the end of each row

       cout<<endl;    }     }

The addRow function begins here

void addRows(int myarray[][5]){

This iterates through the row of the array

   for(int i = 0;i<5;i++){

This initializes the sum of each row to 0

       int rowsum = 0;

This iterates through the columns

       for(int j = 0;j<5;j++){

This adds the elements of each row

           rowsum+=myarray[i][j];        }

This prints the total of each row

       cout<<"Total for row "<<i+1<<" is: "<<rowsum<<endl;    }   }

The highest function begins here

void highest(int myarray[][5]){

This initializes the maximum to 0

   int max = 0;

This iterates through the row of the array

   for(int i = 0;i<5;i++){

This iterates through the columns

       for(int j = 0;j<5;j++){

This checks for the highest

           if(myarray[i][j]>max){

This assigns the maximum to max

               max = myarray[i][j];

           }                    }    }

This prints the max

   cout<<"Highest: "<<max; }

The main method begins here where the array is initialized and each function is called

int main(){

   int myarray[5][5] = {{1,2,3,4,5}, {6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}};

   getNumberr(myarray);

   showNumberr(myarray);

   addRows(myarray);

   highest(myarray);

return 0;

}

Thanks for using our service. We're always here to provide accurate and up-to-date answers to all your queries. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.