帮忙写一个c语言程序,功能:求出二维数组周边元素之和,作为函数值返回。二维数组的值在主函数中赋予。

如题所述

// circ, 计算二元数组周边和

// a [in], 二元数组 

// mo,no,  [in/out], 输入a的行列数, 输出最大元位置 


int circ(int*a, int* mo, int *no){  if(!a || !mo || !no  || *mo<1 || *no<1) return 0; 

int m=*mo, n=*no; 

int ic=m*n, s=0, k, r,c;


for(int i=0; i<ic; i++){

r=i/n; c=i%n; 

if(r==0 || r==m-1 || c==0 || c==n-1) s+=*(a+i);

}  // for 


return s;

}



void t_circ(){

int a[4][4]={

{1,    1,    8, 0,},

{8,    1,    0, 2,},

{6,    0,    9, 4,},

{0,    1,    0, 2,},

};


int m=4, n=4; 


for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ printf("%d\t", a[i][j]);}  printf("\n"); }  // for 


int r=m,c=n,M=circ(a[0],&r,&c);

printf("\nCSum=%d......\n", M);

}



追问

我怎么运行不出来结果?

追答

#include

// 上面的代码.....放在这里

void main(){ t_circ(); }

温馨提示:答案为网友推荐,仅供参考
相似回答