Computer Science, asked by damandeepsingh299, 4 months ago

WAP in java to create a 4*4 matrix and store the different numbers and display the Highest value of each row​

Answers

Answered by chandnaaashman7
0

Answer:

verry eassyy just figure it out

Explanation:

Input :  [1, 2, 3]

        [1, 4, 9]

        [76, 34, 21]

Output :

3

9

76

Input : [1, 2, 3, 21]

       [12, 1, 65, 9]

       [1, 56, 34, 2]

Output :

21

65

56

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach : Approach is very simple. The idea is to run the loop for no_of_rows. Check each element inside the row and find for the maximum element. Finally, print the element.

 

Below is the implementation :

C++

filter_none

edit

play_arrow

brightness_4

// C++ program to find maximum  

// element of each row in a matrix  

#include<bits/stdc++.h>  

using namespace std;  

const int N = 4;  

 

 

   // Print array element  

   void printArray(int result[], int no_of_rows) {  

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

           cout<< result[i]<<"\n";  

       }  

 

   }  

 

   // Function to get max element  

   void maxelement(int no_of_rows, int arr[][N]) {  

       int i = 0;  

         

       // Initialize max to 0 at beginning  

       // of finding max element of each row  

       int max = 0;  

       int result[no_of_rows];  

       while (i < no_of_rows) {  

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

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

                   max = arr[i][j];  

               }  

           }  

           result[i] = max;  

           max = 0;  

           i++;  

 

       }  

       printArray(result,no_of_rows);  

 

   }  

 

   // Driver code  

   int main()  

   {  

       int arr[][N] = { {3, 4, 1, 8},  

                       {1, 4, 9, 11},  

                       {76, 34, 21, 1},  

                       {2, 1, 4, 5} };  

   // Calling the function  

       maxelement(4, arr);  

   }

Answered by anita9570391301
0

Answer:

10 cls

20 input enter a no. E

30 enter four coloums. F

40 input each four rows. H

50 End

Explanation:

please follow me

Similar questions