当前位置:网站首页>[pointer] find the value of the largest element in the two-dimensional array

[pointer] find the value of the largest element in the two-dimensional array

2022-07-06 14:35:00 |Light|

requirement

Compile a function and program to find the value of the largest element in a two-dimensional array .( Use a pointer to achieve )

Code

int find_max(int a[4][4])
{
    
    int *p=&a[0][0],max=a[0][0];
    int i,j,k;
    for(i=0;i<4;i++)
    {
    
        for(j=0;j<4;j++)
        {
    
            if(max < a[i][j])
            max = a[i][j];
        }
    }
    return max;
}

main function

 int main()
 {
    
    int a[4][4],*p;
    int i,j;
    p=&a[0][0];
    for(i=0;i<4;i++)
       for(j=0;j<4;j++)
           scanf("%d",p++);
    printf("%d",find_max(a));
    return 0;
 }   

test

Test input
1 2 3 5
6 5 4 3
7 9 8 3
120 3 32 23
Output
120

原网站

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