| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

```#include <stdio.h>
#include <stdlib.h>
#define N 5
#define M 6
void fun(int (*a)[6],int n,int m,int *odd,int *even);//函数声明。其中odd返回奇数的和，even返回偶数。
int main()
{
int a[N][M]={{1,2,3,4,5,6},{7,8,9,10,11,12},{13,14,15,16,17,18},{19,20,21,22,23,24},{25,26,27,28,29,30}};
int (*p)[M]=a;
int qishu,oushu;
fun(p,5,6,&qishu,&oushu);
printf("qishu_sum=:%d\noushu_sum=:%d",qishu,oushu);
return 0;
}
void fun(int (*a)[6],int n,int m,int *odd,int *even)
{
*odd=0;
*even=0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (*(*(a + i) + j)%2==0)
{
*odd=*odd+*(*(a + i) + j);
}
else if (*(*(a + i) + j)%2==1)
{
*even=*even+*(*(a + i) + j);
}
}
}
return *odd,*even;

}```

```#include <stdio.h>

void fun_v( size_t n, size_t m, int a[n][m], int* odd, int* even )
{
*odd=0, *even=0;
for( size_t r=0; r!=n; ++r )
for( size_t c=0; c!=m; ++c )
*(a[r][c]%2==0?even:odd) += a[r][c];
}

#define fun_m(a,n,m,odd,even) fun_v(n,m,a,odd,even)

int main( void )
{
int a[5][6] = {{1,2,3,4,5,6},{7,8,9,10,11,12},{13,14,15,16,17,18},{19,20,21,22,23,24},{25,26,27,28,29,30}};

int odd, even;
fun_v( 5, 6, a, &odd, &even );
printf( "odd=%d, even=%d\n", odd, even );

fun_m( a, 5, 6, &odd, &even );
printf( "odd=%d, even=%d\n", odd, even );
}```

#include <stdio.h>

void fun(int a[5][6], int n, int m, int *odd, int *even)
{
*odd = 0;
*even = 0;
int* p = (int*)a;
int i;
for (i=0;i<n*m; ++i)
{
if (p[i]&1)
*odd += p[i];
else
*even += p[i];
}
}

int main(void)
{
int a[5][6] = {{1,2,3,4,5,6},{7,8,9,10,11,12},{13,14,15,16,17,18},{19,20,21,22,23,24},{25,26,27,28,29,30}};
int odd, even;
fun(a, 5, 6, &odd, &even);
printf( "odd=%d, even=%d\n", odd, even);
}
• 4
• 1/1页
• 1