Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

return largerst line from 2D array

I need help with a function that finds the line with the largest number of numbers in a two-dimensional array and prints index this row. I don’t know how to start for help thank you.

main.c

int array[2][2]=  { {1,0}, {0,3} };
printf("%d\n", largest_line(2, array));

int largest_line(const int size, int array[][size]){

for(int col= 0; col < size; col++){
    for(int row = 0; row <size; row++){
     // and on this place I stop 
    }
}
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Something like this should work for you:

int largest_line(const int size, int array[][size]){

    int largest_number = 0;
    int largest_row = 0;

    for(int col= 0; col < size; col++){
        for(int row = 0; row <size; row++){
            if(largest_number > array[col][row]) {
                largest_number = array[col][row]);
                largest_row = row;
            }
        }
    }
    return largest_row;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading