MouseyN1

Minimul unei matrice (functie)

Oct 5th, 2012
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. /*
  2. 21  Se considera o matrice patratica. Sa se calculeze elementul minim din matrice folosind un subprogram
  3. de tip functie care primeste ca parametru matricea.
  4. */
  5.  
  6. #include <iostream>
  7. using namespace std;
  8. void citireMatrice(int a[100][100], int &n)
  9. {
  10.     cin >> n;
  11.     for(int i = 1; i <= n; i++)
  12.         for(int j = 1; j <= n; j++)
  13.             cin >> a[i][j];
  14. }
  15.  
  16. void afisareMatrice(int a[100][100], int n)
  17. {
  18.     cout << endl;
  19.     for(int i = 1; i <= n; i++) {
  20.         for(int j = 1; j <= n; j++)
  21.             cout << a[i][j] << " ";
  22.         cout << endl;
  23.     }
  24. }
  25.  
  26. int minMatrice(int a[100][100], int n)
  27. {
  28.     int min = INT_MAX;
  29.     for(int i = 1; i <= n; i++)
  30.     {
  31.         for(int j = 1; j <= n; j++)
  32.             if(a[i][j] < min)
  33.                 min = a[i][j];
  34.     }
  35.     return min;
  36. }
  37.  
  38. int main()
  39. {
  40.     int a[100][100], n;
  41.     citireMatrice(a, n);
  42.     afisareMatrice(a, n);
  43.     cout << endl << "Elementul minim din matrice este: " << minMatrice(a, n);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment