返回列表 發帖
本帖最後由 何權晉 於 2024-10-11 20:57 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. int main()
  4. {
  5.     int a1,b2,a2,b2;
  6.     cin>>a1>>b1;
  7.     int arr1[a1][b1];
  8.     for(int i=0;i<a1;i++)
  9.         for(int j=0;j<b1;j++)
  10.         cin>>arr1[i][j];
  11.         
  12.     int arr2[a2][b2]
  13.     for(int i=0;i<a2;i++)
  14.         for(int j=0;j<b2;j++)
  15.         cin>>arr2[i][j];
  16.         
  17.         if(b1!=a2)
  18.             cout<<"error";
  19.         else
  20.         {
  21.             for(int i=0;i<a1;i++)
  22.                 for(int j=0;j<b2;j++)
  23.             {
  24.                 int sum=0;
  25.                 for(int k=0;k<b1;k++)
  26.                     sum+=arr1[i][k]*arr2[k][j];
  27.                 if(j!=0)
  28.                     cout<<" ";
  29.                 cout<<sum;
  30.             }
  31.             cout<<endl;
  32.         }
  33.     return 0;
  34. }
複製代碼

TOP

返回列表