Welcome Guest.

1Answers

Programming for a two -dimensional array

Asked by: Marilyn Turner 7 views IT June 23, 2022

A [4] [4] = {{23,34, -1,2}, {6,78, -54,20}, {18, -15,0,45}, {36,58,,67,37}}; maximum value, and output the maximum value of two -dimensional array

1 Answers

  1. +8Votes  

    If you only need to find the maximum number, you can create a new variable to access the maximum read.Traversing the array, each time you traverse the element, compare this element and variable value. If it is greater than the variable value, the variable value is replaced, otherwise it will not care, and then continue to traversed. The code is as follows:

    int a[4] [4] = {{23,34, -1,2}, {6,78, -54,20}, {18, -15,0,45}, {36,58,67,37}};

    int Max = 0;

    for (int i = 0; i <4; i ++)

    {

    for (int j = 0; j <4; j ++)

    {

    if (a [i] [j]> max)

    {{

    max = a [i] [j];

    }

    }

    Running like thisIn the end, the value of the variable MAX is the maximum value in the array.

    Frank Murphy- June 23, 2022 |

Answer Question