当前位置:网站首页>Find out the maximum value of each column element of NxN matrix and store it in the one-dimensional array indicated by formal parameter B in order

Find out the maximum value of each column element of NxN matrix and store it in the one-dimensional array indicated by formal parameter B in order

2022-06-26 16:44:00 Muzi..

#include<stdio.h>
#define N 4
void fun(int (*a)[N],int *b);
int main()
{
    
	 int x[N][N]={
    {
    12,5,8,7},{
    6,1,9,3},{
    1,2,3,4},{
    2,8,4,3}};
	 int y[N],i,j;
	 printf("the matrix:\n");
	 for(i=0;i<N;i++)
	 {
    
	 	 for(j=0;j<N;j++)
	 	 
	 	 	 printf("%4d",x[i][j]);
	 	 	 printf("\n");
		  
	 }
	 fun(x,y);
	 printf("\n the result is:");
	 for(i=0;i<N;i++)
	  printf("%3d",y[i]);
	  printf("\n");
}
void fun(int (*a)[N],int *b)
{
    
	 int i,j;
	 for(i=0;i<N;i++)
	  {
    
	     b[i]=a[0][i];
	     for(j=1;j<N;j++)
	        if(b[i]<a[j][i])
	         b[i]=a[j][i];
       }
}
                                                                                

原网站

版权声明
本文为[Muzi..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170506478018.html