一道C语言程序题,求大神帮忙!!!

2024-12-31 05:31:06
推荐回答(2个)
回答1:

#include
#define M 2
#define N 4
int main()
{
int sumcolummin(int a[N]);
int x[M][N]={3,2,5,1,4,1,8,3},s,i,j,min[N];
for(j=0;j{
min[j]=x[0][j];
for(i=0;i {
if(x[i][j] min[j]=x[i][j];
}
printf("min[%d]=%d\n",j,min[j]);
}
s=sumcolumin(min);
printf("s=%d\n",s);
}
int sumcolumin(int a[N])
{
int j,sum=0;
for(j=0;j {
sum=sum+a[j];
}
return(sum);
}

回答2:

#include "stdio.h"
#define M 2
#define N 4
void SumColumMin(int a[M][N],int *sum)
{
int j,min;
*sum = 0;
for(int i = 0;i < N;i++)
{
min = a[0][i];
for(j = 0;j < M;j++)
if (min > a[j][i])
min = a[j][i];
*sum = *sum + min;
}
}
void main()
{
int x[M][N]={3,2,5,1,4,1,8,3},s;
SumColumMin(x,&s);
printf("%d\n",s);
}