⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 madd.cpp

📁 data structures, algorithms and Application书的源代码
💻 CPP
字号:
// matrix addition

#include <iostream.h>
#include "make2db.h"

template<class T>
void Add( T **a, T **b, T **c, int rows, int cols)
{// Add matrices a and b to obtain matrix c.
   for (int i = 0; i < rows; i++)
      for (int j = 0;  j < cols; j++)
         c[i][j] = a[i][j] + b[i][j];
}

void main(void)
{
   int **a, **b, **c;
   Make2DArray(a,2,2);
   Make2DArray(b,2,2);
   Make2DArray(c,2,2);
   a[0][0] = 1; a[0][1] = 2; a[1][0] = 3; a[1][1] = 4;
   b[0][0] = 1; b[0][1] = 2; b[1][0] = 3; b[1][1] = 4;
   Add(a,b,c,2,2);
   cout << c[0][0] << ' ' << c[0][1] << endl;
   cout << c[1][0] << ' ' << c[1][1] << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -