401,829 views
40 votes
40 votes
6. Write a C++ program to print the largest three elements in an array.


User Jagdish
by
3.1k points

1 Answer

9 votes
9 votes

Answer:

if (arr[i] > max) -> max3 = max2, max2 = max , max = arr[i]. else if (arr[i] > max2) -> max3 = max2, max2 = arr[i]. else if (arr[i] > max3) -> max3 = arr[i]. At the end of the loop, we will print all three values.

User Pankaj Singhal
by
3.2k points