返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a1,b1,a2,b2;
  4. int main()
  5. {
  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.         {
  11.             cin>>arr1[i][j];
  12.         }
  13.     cin>>a2>>b2;
  14.     int arr2[a2][b2];
  15.     for(int i=0;i<a2;i++)
  16.         for(int j=0;j<b2;j++)
  17.         {
  18.             cin>>arr2[i][j];
  19.         }
  20.     if(b1!=a2)
  21.     {
  22.         cout<<"error"<<endl;
  23.     }
  24.     else
  25.     {
  26.         for(int i=0;i<a1;i++)
  27.         {
  28.             for(int j=0;j<b2;j++)
  29.             {
  30.                 int sum=0;
  31.                 for(int k=0;k<b1;k++)
  32.                     sum+=arr1[i][k]*arr2[k][j];
  33.                 if(j!=0)
  34.                     cout<<" ";
  35.                 cout<<sum;
  36.             }
  37.             cout<<endl;
  38.         }
  39.     }
  40.     return 0;

  41. }
複製代碼

TOP

返回列表