高手来指导一下VC

来源:百度知道 编辑:UC知道 时间:2024/06/24 09:28:09
#include<iostream.h>
int i,j;
const int M=4,N=4;
void input(int a[][M],int N,int M);
int sumA(int a[][M],int M);
void main()
{
int a[N][M],sumA[M]={0};
input(a,N,M);
sumA(a,M);
for(j=0;j<M;j++)
cout<<sumA[j]<<"\t";

}

void input(int a[N][M])
{

cout<<"please enter the array:\n";
for(i=0;i<N;i++)
for(j=0;j<M;j++)
cin>>a[i][j];
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
}

int sumA(int a[][M],int M)
{
for(j=0;j<M;j++)
{
for(i=0;i<N;i++)
sumA[j]+=a[i][j];
}
return sumA[j];

}

这个怎么不对?

不要把变量名和函数名起一样了,这是一种非常恶劣的编程习惯。
全局变量名不能和函数名相同,你把你那个samA的数组或者samA函数换个名字就可以了。
你在sumA函数中使用了main函数中定义的sumA数组,太乱了。