Advertisement
MouseyN1

Afisarea elementelor de pe diagonala (matrice patratica)

May 7th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. // Se citeste o matrice patratica, elementele de pe diag. principala pe primul rand, el. de pe diag. secundara pe al doilea rand.
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5. int main()
  6. {
  7.     int a[100][100], n, i, j, k(1);
  8.     cout << "Introduceti numarul de linii/coloane: ";
  9.     cin >> n;
  10.     for(i = 1; i <= n; i++)
  11.         for(j = 1; j <= n; j++)
  12.         {
  13.             a[i][j] = k++;
  14.         }
  15.     for(i = 1; i <= n; i++)
  16.     {
  17.         for(j = 1; j <= n; j++)
  18.             cout << setw(3) << a[i][j] << " ";
  19.         cout << endl;
  20.     }
  21.     cout << endl;
  22.     for(i = 1; i <= n; i++)
  23.         cout << a[i][i] << " ";
  24.     cout << endl;
  25.     for(i = 1; i <= n; i++)
  26.         cout << a[i][n+1-i] << " ";
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement