Seeking the maximum values of the matrix elements, and the line number and column number

Seeking the maximum values ​​of the matrix elements, and the line number and column number




Code:

#include <stdio.h> 

int a[2] = {0, 0};

void func(int array[3][4]) 
{
    int i, j, t = array[0][0];
    for(i = 0; i < 3; i++) 
    {
        for(j = 0; j < 4; j++)
        {
            if(array[i][j]>t) 
            {
                t = array[i][j];
                a[0] = i;
                a[1] = j;
            } 
        }
    } 
}

int main()
{
    int b[3][4] = {
        {1, 5 ,7},
        {2, 10, 3},
        {5, 9, 7}
    };
    func(b);
    printf("%d %d %d", b[a[0]][a[1]], a[0] + 1, a[1] + 1); 
    
    return 0;
}

Function void func(int array[3][4])is used to find the maximum number of matrix row and column numbers stored in the array a.

Guess you like

Origin www.cnblogs.com/huochemeiyouhuo/p/11223057.html