Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int n, **A, **B, **C;
- cout << ("Nhap n = ");
- cin >> n;
- // cap phat bo nho
- A = new int*[n];
- B = new int*[n];
- C = new int*[n];
- for(int i = 0; i < n; i++){
- A[i] = new int[n];
- B[i] = new int[n];
- C[i] = new int[n];
- }
- // nhap cac phan tu
- for(int i = 0; i < n; i++)
- for(int j = 0; j < n; j++){
- cout << "A[" << i << "][" << j << "] = ";
- cin >> A[i][j];
- }
- for(int i = 0; i < n; i++)
- for(int j = 0; j < n; j++){
- cout << "B[" << i << "][" << j << "] = ";
- cin >> B[i][j];
- }
- // tinh tong ma tran
- for(int i = 0; i < n; i++)
- for(int j = 0; j < n; j++){
- C[i][j] = A[i][j] + B[i][j];
- }
- cout << "Tong hai ma tran la: \n";
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++)
- cout << C[i][j] << " ";
- cout << "\n";
- }
- // tinh tich ma tran
- for(int i = 0; i < n; i++)
- for(int j = 0; j < n; j++){
- C[i][j] = 0;
- for(int k = 0; k < n; k++)
- C[i][j] += A[i][k]*B[k][j];
- }
- cout << "Tich hai ma tran la: \n";
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++)
- cout << C[i][j] << " ";
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment