DMG

Formiranje niza (razlika u koloni)

DMG
Mar 22nd, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. /* Formiranje niza tako sto je b[j] jednak razlici maximalnog i minimalnog clana kolone */
  2. #include <iostream>
  3. using namespace std;
  4. main()
  5. {
  6.       int a[50][50], b[50], m, n, i, j, max, min;
  7.       cin >> m >> n;
  8.       for (i=0; i<m; i++)
  9.       for (j=0; j<n; j++)
  10.       cin >> a[i][j];
  11.       for (j=0; j<n; j++)
  12.       {
  13.           max = a[0][j];
  14.           min = a[0][j];
  15.           for (i=1; i<m; i++)
  16.           {
  17.               if (a[i][j] > max)
  18.               max = a[i][j];
  19.               if (a[i][j] < min)
  20.               min = a[i][j];          
  21.           }
  22.           b[j] = max - min;
  23.       }
  24.      
  25.       cout << endl;
  26.      /* Stampanje matrice */
  27.      /* for (i=0; i<m; i++)
  28.       {
  29.           for (j=0; j<n; j++)
  30.           cout << a[i][j] << " ";
  31.           cout << endl;
  32.       }
  33.       */
  34.      
  35.       for (j=0; j<n; j++)
  36.       cout << b[j] << " ";
  37.       system ("PAUSE");
  38. }
Advertisement
Add Comment
Please, Sign In to add comment