Rephrasing question newbie loop

Let me rephrase the question in this page(newbie loop c++. please explain efficient looping - general - CodeChef Discuss) because there seems to be a confusion.

Straight to the point.

can anybody suggest another algorithm that would make this code run shorter.

for(int x = 0; x < 4; x++)
for(int y = 0; y < 5; y++)
{
if(largest < a[x][y])
largest = a[x][y];
if(smallest > a[x][y])
smallest = a[x][y];
}

it is observed that it will iterate 20 times, is it possible to make the iteration shorter but still work with the same output? (getting the largest and smallest in an array) We are obliged by our prof not to use advance constructs.

NO it is not possible. Think about it this way, there lie 20 chits of paper in front of you and you need to find the largest and smallest number. Without opening all 20 chits you can’t find the largest and smallest. The same logic applies to the computer. You must have misheard your prof.

1 Like