1.创建文件EWDemo.h:
2.EWDemo.h文件代码:
#ifndef EWDEMO_H_INCLUDED
#define EWDEMO_H_INCLUDED
//二维数组的传参
#include <iostream>
using namespace std;
void show(double (*)[5],int); //定义原型
//函数实现
void show(double (*arrs)[5],int len){
for(int i=0;i<len;i++){
for(int j=0;j<5;j++){
cout << arrs[i][j] << "\t";
}
cout << endl;
}
}
#endif // EWDEMO_H_INCLUDED
3.引用该函数:
#include <iostream>
#include "EWDemo.h" //引用头文件夹里的EWDemo.h文件
using namespace std;
int sum(int,int);
int main()
{
//打印二维数组
double powers[3][5] = {
{54.4,59.2,25.5,52.6,44},
{84.4,29.4,35.5,51.6,45},
{52.4,57.2,24.5,52.6,46}
};
show(powers,3); //调用方法
}
- 运行结果: