Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- struct matran {
- int n;
- int **a;
- };
- void nhap(matran &a)
- {
- cout << "Nhap cap ma tran: ";
- cin >> a.n;
- a.a = new int*[a.n];
- for (int i=0; i<a.n; i++)
- a.a[i] = new int[a.n];
- for (i=0; i<a.n; i++)
- for (int j=0; j<a.n; j++)
- {
- cout << "Nhap a[" << i+1 << "][" << j+1 << "]: ";
- cin >> a.a[i][j];
- }
- }
- void in (matran a)
- {
- for (int i=0; i<a.n; i++)
- {
- for (int j=0; j<a.n; j++)
- cout << setw(6) << a.a[i][j];
- cout << endl;
- }
- }
- matran operator - (matran a)
- {
- int i;
- matran b;
- b.n = a.n;
- b.a = new int*[b.n];
- for (i=0; i<b.n; i++)
- b.a[i] = new int [b.n];
- for (i=0; i<b.n; i++)
- for (int j=0; j<b.n; j++)
- b.a[i][j] = -a.a[i][j];
- return b;
- }
- main ()
- {
- matran a,b;
- nhap(a);
- cout << endl << "Ma tran A: " << endl;
- in(a);
- b=-a;
- cout << endl << "Ma tran B: " << endl;
- in(b);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement