MouseyN1

Parcurgere matrici

Apr 23rd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. // Parcurgerea unei matrici
  2. // a) afisare normala
  3. // b) coloane de jos in sus
  4. // c) elementele de pe contur
  5.  
  6. #include <iostream>
  7. using namespace std;
  8. int main()
  9. {
  10.     int i, j, m, n, a[100][100];
  11.     cout << "Introduceti numarul de linii: ";
  12.     cin >> n;
  13.     cout << "Introduceti numarul de coloane: ";
  14.     cin >> m;
  15.     for(i = 1; i <= n; i++)
  16.         for(j = 1; j <= m; j++) {
  17.             cout << "a[" << i << "][" << j << "]=";
  18.             cin >> a[i][j];
  19.         }
  20.     cout << endl << "Parcurgerea normala a matricei: \n";
  21.     for(i = 1; i <= n; i++) {
  22.         for(j = 1; j <= m; j++)
  23.             cout << a[i][j] << " ";
  24.         cout << endl;
  25.     }
  26.     cout << "\n\n\nParcurgerea pe coloane de jos in sus: \n";
  27.     for(i = n; i >= 1; i--) {
  28.         for(j = 1; j <= m; j++)
  29.             cout << a[i][j] << " ";
  30.         cout << endl;
  31.     }
  32.     cout << "\n\n\nParcurgerea elementelor de pe contur: \n";
  33.     for(j = 1; j <= m; j++)
  34.         cout << a[1][j] << " ";
  35.     for(i = 2; i < n; i++)
  36.         cout << a[i][m] << " ";
  37.     for(j = m; j >= 1; j--)
  38.         cout << a[n][j] << " ";
  39.     for(i = n - 1; i > 1; i--)
  40.         cout << a[i][1] << " ";
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment