二维数组求每行每列的和改错

来源:百度知道 编辑:UC知道 时间:2024/05/23 01:27:04
#include <iostream>
using namespace std;
int sum(int a[][],int m,int n);
int main()
{
int m,n,i,j;
int a[10][10];
cout<<"Please input the numbers of the rows and columns of the array matrix:";
cin>>m>>n;
cout<<"Please enter the array:"<<endl;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
cout<<"a"<<i<<" "<<j<<":";
cin>>a[i][j];
}
sum(a[][],m,n);
return 0;
}
int sum(int a[10][10],int m,int n)
{
int i,j;
int sumr[10];
int sumc[10];
for(i=0;i<m;i++)
{
sumr[i]=0;
for(j=0;j<n;j++)
{
sumr[i]+=a[i][j];
}
cout<<"The sum of row "<<i<<" is:"<<sumr[i]<<endl;
}

for(j=0;j<n;j++)
{
sumc[j]=0;
for(i=

第三行:改为int sum(int a[][10],int m,int n);
调用时:改为sum(a,m,n);

int sum(int a[(这里加个参数看看)]

#include <iostream>
using namespace std;
int sum(int a[][10],int m,int n); //修改1

int main()
{
int m,n,i,j;
int a[10][10];
cout<<"Please input the numbers of the rows and columns of the array matrix:";
cin>>m>>n;
cout<<"Please enter the array:"<<endl;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
cout<<"a"<<i<<" "<<j<<":";
cin>>a[i][j];
}
sum(a,m,n); //修改2
return 0;
}

int sum(int a[10][10],int m,int n)
{
int i,j;
int sumr[10];
int sumc[10];
for(i=0;i<m;i++)
{
sumr[i]=0;
for(j=0;j<n;j++)
{
sumr[i]+=a[i][j];
}
cout<<"The su