作者在 2010-06-05 11:19:20 发布以下内容
#include"iostream.h"
#include"iomanip.h"
const int M=3;
const int N=4; //列大小
int main() //a,b数组设置初值
{int a[M][N]={{11,22,33,44},{20,30,40,50},{31,41,51,61}},b[M][N]={{50,24,43,42},{75,74,78,27},{23,56,35,23}},c[M][N];
int i,j;
cout<<"a数组值:\n";
for(i=0;i<M;i++)
{for(j=0;j<N;j++)
cout<<setw(4)<<a[i][j];
cout<<endl;
}
cout<<"b数组值:\n";
for(i=0;i<M;i++)
{for(j=0;j<N;j++)
cout<<setw(4)<<b[i][j];
cout<<endl;
}
//数组相加
for(i=0;i<M;i++)
{for(j=0;j<N;j++)
c[i][j]=a[i][j]+b[i][j]; //元素相加
}
cout<<"c数组值:\n";
for(i=0;i<M;i++)
{for(i=0;i<N;i++)
cout<<setw(4)<<c[i][j];
cout<<endl;
}
return 0;
}
#include"iomanip.h"
const int M=3;
const int N=4; //列大小
int main() //a,b数组设置初值
{int a[M][N]={{11,22,33,44},{20,30,40,50},{31,41,51,61}},b[M][N]={{50,24,43,42},{75,74,78,27},{23,56,35,23}},c[M][N];
int i,j;
cout<<"a数组值:\n";
for(i=0;i<M;i++)
{for(j=0;j<N;j++)
cout<<setw(4)<<a[i][j];
cout<<endl;
}
cout<<"b数组值:\n";
for(i=0;i<M;i++)
{for(j=0;j<N;j++)
cout<<setw(4)<<b[i][j];
cout<<endl;
}
//数组相加
for(i=0;i<M;i++)
{for(j=0;j<N;j++)
c[i][j]=a[i][j]+b[i][j]; //元素相加
}
cout<<"c数组值:\n";
for(i=0;i<M;i++)
{for(i=0;i<N;i++)
cout<<setw(4)<<c[i][j];
cout<<endl;
}
return 0;
}