fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int dong, cot;
  6. cout << "Nhap so dong va cot: ";
  7. cin >> dong >> cot;
  8.  
  9. int a[100][100];
  10. // Nhap ma tran
  11. for(int i=0; i<dong; i++)
  12. for(int j=0; j<cot; j++)
  13. cin >> a[i][j];
  14.  
  15. // Tinh tong theo cot
  16. for(int j=0; j<cot; j++) {
  17. int tongCot = 0; // Khoi tao tong cot moi
  18. for(int i=0; i<dong; i++) {
  19. tongCot += a[i][j]; // Cong tung phan tu trong cot
  20. }
  21. cout << "Tong cot " << j+1 << ": " << tongCot << endl;
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5284KB
stdin
3 3
stdout
Nhap so dong va cot: Tong cot 1: 0
Tong cot 2: 0
Tong cot 3: 0