60 (find the largest element in each column)

60 date: 2021.3.7
Insert picture description here
Key points:

The detailed code is as follows:

#include    <conio.h>
#include    <stdio.h>
#include	<stdlib.h>
#define  M  3
#define  N  4
void fun(int  tt[M][N],int  pp[N])
{
    
    
	/*
		analyse:


	*/


	int i ,j,k = 0;
	

	for( j =0; j < N; j++)  //列
	{
    
    
		int max = tt[0][j];  //tt[j][0] 是错误的
		for( i = 0; i < M; i++)
		{
    
    
			
			 if(max < tt[i][j])
				 max = tt[i][j];
		}
		pp[k++] = max; //pp[j] = max;亦可
	}

	
}


void main( )
{
    
    
   void NONO( );
	int t[M][N]={
    
    {
    
    68, 32, 54, 12},{
    
    14, 24, 88, 58},{
    
    42, 22, 44, 56}};
   int  p [ N ],  i,  j,  k;
   printf ( "The original data is : \n" );
   for( i=0; i<M; i++ ){
    
    
     for( j=0; j<N; j++ )
       printf ( "%6d", t[i][j] );
     printf("\n");
   }
   fun ( t, p );
   printf( "\nThe result  is:\n" );
   for ( k = 0; k < N; k++ ) printf ( " %4d ", p[ k ] );
   printf("\n");
   NONO( );
}

Guess you like

Origin blog.csdn.net/weixin_44856544/article/details/114504603