Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Se citeste o matrice patratica, elementele de pe diag. principala pe primul rand, el. de pe diag. secundara pe al doilea rand.
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int a[100][100], n, i, j, k(1);
- cout << "Introduceti numarul de linii/coloane: ";
- cin >> n;
- for(i = 1; i <= n; i++)
- for(j = 1; j <= n; j++)
- {
- a[i][j] = k++;
- }
- for(i = 1; i <= n; i++)
- {
- for(j = 1; j <= n; j++)
- cout << setw(3) << a[i][j] << " ";
- cout << endl;
- }
- cout << endl;
- for(i = 1; i <= n; i++)
- cout << a[i][i] << " ";
- cout << endl;
- for(i = 1; i <= n; i++)
- cout << a[i][n+1-i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement