Advertisement
Emanuele_Bruno

Esame 6

Dec 6th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int RIG=4, COL=4;
  6. const long A[][COL]={{1,2,3,4},
  7.                      {5,6,7,8},
  8.                      {9,0,1,2},
  9.                      {3,4,5,6}};
  10.  
  11. long sommatoria (const long A[][COL],const int RIG);
  12.  
  13. int main()
  14. {
  15.     cout << "La sommatoria degli elementi piu' grandi in ogni riga della matrice A e' = " << sommatoria (A,RIG);
  16.     return 0;
  17. }
  18.  
  19. long sommatoria (const long A[][COL],const int RIG)
  20. {
  21.     int i=0,k;
  22.     long max_elem=0,temp;
  23.     while (i<RIG)
  24.     {
  25.         k=0;
  26.         temp=0;
  27.         while (k<COL)
  28.         {
  29.             if (A[i][k]>temp) temp=A[i][k];
  30.             k++;
  31.         }
  32.         max_elem+=temp;
  33.         i++;
  34.     }
  35.     return max_elem;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement