这片文章介绍了如何利用二维动态数组指针做矩阵运算,需要的朋友可以参考下
本文分享了利用二维动态数组指针做矩阵运算的实现代码。
1. 头文件
- // juzhen 2.cpp : Defines the entry point for the console application. //
- #include "stdafx.h"
- #include "stdlib.h" #include "windows.h"
- #define OK 0 #define NG -1
- typedef struct mat {
- int nRow; /* 行数 */ int nCol; /* 列数 */
- int* pData; /* 指向矩??体的指? */ }MAT;
2. 程序代码
- #include "stdafx.h" #include "Matrix_cal.h"
- /* Entity and initial matrix of the application matrix function */ int MATAlloc(MAT *pMat, int nRow, int nCol)
- { pMat->pData = (int *) malloc (nRow * nCol * sizeof(int) );
- if(NULL == pMat->pData) {
- printf("Memary is error!n"); return NG;
- } for(int i=0; i<nRow; ++i)
- { for(int j=0; j<nCol; ++j)
- { *(pMat->pData + i*nCol + j)=0;
- } }
- pMat->nRow = nRow; pMat->nCol = nCol;










