在函数中添加,减去,乘以矩阵

时间:2015-09-08 20:40:22

标签: c++ matrix

#include<iostream>

using namespace std;

main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];

cout << "Enter the number of rows and columns of matrix ";
cin >> m >> n;
cout << "Enter the elements of first matrix\n";

for (  c = 0 ; c < m ; c++ )
  for ( d = 0 ; d < n ; d++ )
     cin >> first[c][d];

cout << "Enter the elements of second matrix\n";

for ( c = 0 ; c < m ;c++ )
  for ( d = 0 ; d < n ; d++ )
        cin >> second[c][d];

for ( c = 0 ; c < m ; c++ )
  for ( d = 0 ; d < n ; d++ )
     sum[c][d] = first[c][d] + second[c][d];

cout << "Sum of entered matrices:-\n";

for ( c = 0 ; c < m ; c++ )
{
  for ( d = 0 ; d < n ; d++ )
     cout << sum[c][d] << "\t";

  cout << endl;
}

return 0;
}

大家好,所以我在网上发现这个源代码添加了两个矩阵,但我有几个问题要问: 为什么第一[10] [10],第二[10] [10],sum [10] [10]宣称有一个10号阵列?

另外,为了减少这个,我只需改变符号和其他一些东西吧?

乘法怎么样?对此有何解释?谢谢你们。

1 个答案:

答案 0 :(得分:2)

  

为什么第一[10] [10],第二[10] [10],sum [10] [10]被宣布为10号阵列?

该计划的作者假设最大可能的矩阵大小为10乘10。 如果需要,可以添加缩小它的大小。

  

另外,为了减少这个,我只需改变符号和其他一些东西吧?

sum[c][d] = first[c][d] + second[c][d]; //Do what you want with this 
  

乘法怎么样?对此有何解释?

尝试使用笔和纸,然后转换为代码。

有用的链接:

享受。

相关问题