请编写函数int fun ,a是一个M行N列的二维数组,函数的功能是求出二维数组周边元素之和,作为函数值返回.#include #include #define M 4#define N 5int fun ( int a[M][N] ){ }NONO( ){/* 请在此函数内打开文件,输入测试数据,调用 fun 函数, 输出数据,关闭文件.*/ int i,j,y,k,aa[M][N] ; FILE *rf,*wf ; rf = fopen("bc4.in","r") ; wf = fopen("bc4.out","w") ; for(k = 0 ; k < 10 ; k++) { for(i = 0 ; i < M ; i++) for(j = 0 ; j < N ; j++) fscanf(rf,"%d",&aa[i][j]) ; y = fun ( aa ); fprintf(wf,"%d\n",y) ;
请编写函数int fun ,a是一个M行N列的二维数组,函数的功能是求出二维数组周边元素之和,作为函数值返回.
#include <conio.h>#include <stdio.h>#define M 4#define N 5int fun ( int a[M][N] ){ }NONO( ){/* 请在此函数内打开文件,输入测试数据,调用 fun 函数, 输出数据,关闭文件.*/ int i,j,y,k,aa[M][N] ; FILE *rf,*wf ; rf = fopen("bc4.in","r") ; wf = fopen("bc4.out","w") ; for(k = 0 ; k < 10 ; k++) { for(i = 0 ; i < M ; i++) for(j = 0 ; j < N ; j++) fscanf(rf,"%d",&aa[i][j]) ; y = fun ( aa ); fprintf(wf,"%d\n",y) ; } fclose(rf) ; fclose(wf) ;}main( ){ int aa[M][N]={{1,3,5,7,9}, {2,9,9,9,4}, {6,9,9,9,8}, {1,3,5,7,0}}; int i,j,y; printf ( "The original data is :\n" ); for ( i=0; i<M; i++ ) { for ( j =0; j<N; j++ ) printf( "%6d",aa[i][j] ); printf ("\n"); } y = fun ( aa ); printf( "\nThe sum: %d\n" ,y ); printf("\n"); NONO( );}
我已经测试 结果61!
int fun ( int a[M][N] )
{
int i,j,sum=0;
for(i=1;i