65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
void input_matrix(double**&buffer,int &N); // 用引用
int main()
{
double **buffer=NULL;
int N=0;//方阵的阶数
input_matrix(buffer,N);//输入N阶矩阵
//************在主函数内显示输入的矩阵******************/
for(int i=0;i <N;i++)
{
for(int j=0;j <N;j++)
{
cout <<buffer[i][j] <<" ";
}
cout <<endl;
}
//*******************************/
return 0;
}
void input_matrix(double ** &buffer,int &N) //用引用
{
int i,j;
cout <<"请输入方阵的阶数" <<endl;
cin>>N;
buffer=new double *[N];//指针数组
for( j=0;j <N;j++)
{
buffer[j]=new double [N];
}
cout <<"请输入方阵的元素:" <<endl;
for( i=0;i <N;i++)
{
for( j=0;j <N;j++)
{
cin>>buffer[i][j];
}
}
//******************在input_matix()内显示输入的矩阵****************************/
/*for(i=0;i <N;i++)
{
for( j=0;j <N;j++)
{
cout <<buffer[i][j] <<" ";
}
cout <<endl;
}*/
//***********************************************/
}
#include <iostream>
using namespace std;
void input_matrix(double**&buffer,int &N); // 用引用
int main()
{
double **buffer=NULL;
int N=0;//方阵的阶数
input_matrix(buffer,N);//输入N阶矩阵
//************在主函数内显示输入的矩阵******************/
for(int i=0;i <N;i++)
{
for(int j=0;j <N;j++)
{
cout <<buffer[i][j] <<" ";
}
cout <<endl;
}
//*******************************/
return 0;
}
void input_matrix(double ** &buffer,int &N) //用引用
{
int i,j;
cout <<"请输入方阵的阶数" <<endl;
cin>>N;
buffer=new double *[N];//指针数组
for( j=0;j <N;j++)
{
buffer[j]=new double [N];
}
cout <<"请输入方阵的元素:" <<endl;
for( i=0;i <N;i++)
{
for( j=0;j <N;j++)
{
cin>>buffer[i][j];
}
}
//******************在input_matix()内显示输入的矩阵****************************/
/*for(i=0;i <N;i++)
{
for( j=0;j <N;j++)
{
cout <<buffer[i][j] <<" ";
}
cout <<endl;
}*/
//***********************************************/
}