Advertisement
gosuodin

Nhan 2 ma tran

May 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define MAX 100
  4. int main() {
  5. int a[MAX][MAX];
  6. int b[MAX][MAX];
  7. int soDong, soCot, soDong1, soCot1;
  8. int tong = 0;
  9. cout << "NHap so dong:";
  10. cin >> soDong;
  11. cout << "nhap so cot :";
  12. cin >> soCot;
  13. for (int i = 0; i < soDong; i++) {
  14. for (int j = 0; j < soCot; j++) {
  15. cout << "Nhap a[" << i+1<< "][" << j+1 << "]";
  16. cin >> a[i][j];
  17. }
  18. }
  19. cout << "\t" << "MA TRAN A" << endl;
  20. for (int i = 0; i < soDong; i++) {
  21. for (int j = 0; j < soCot; j++) {
  22. cout <<"\t"<< a[i][j];
  23. }
  24. cout << endl;
  25. }
  26. cout << "NHap so dong:";
  27. cin >> soDong1;
  28. cout << "nhap so cot :";
  29. cin >> soCot1;
  30. for (int i = 0; i < soDong1; i++) {
  31. for (int j = 0; j < soCot1; j++) {
  32. cout << "Nhap a[" << i+1<< "][" << j+1 << "]";
  33. cin >> b[i][j];
  34. }
  35.  
  36. }
  37. cout << "\t" << "MA TRAN B" << endl;
  38. for (int i = 0; i < soDong1; i++) {
  39. for (int j = 0; j < soCot1; j++) {
  40. cout << "\t" << b[i][j];
  41. }
  42. cout << endl;
  43. }
  44. // Nhanma tran
  45. cout << "Nhan 2 ma tran" << endl;
  46. for (int i = 0; i < soDong; i++)
  47. for (int j = 0; j<soCot1; j++)
  48. {
  49.  
  50. for(int k = 0; k < soDong1; k++)
  51. for(int l=0;l<soCot;l++){
  52. tong = tong + a[i][l ] * b[k][j];
  53. }
  54. cout << endl;
  55. }
  56. for (int i = 0; i < soDong;i++) {
  57. for (int j = 0; j < soCot; j++) {
  58. cout << "\t" <<tong;
  59. }
  60. cout << endl;
  61. }
  62.  
  63. system("pause>NULL");
  64. return 0;
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement