โ Back to Arrays
Question 98
Find the Largest Element
Find the Largest Element
An array called nums has already been created for you with the values {10, 40, 20, 50, 30}. Notice the values are not in order.
A variable called max has been initialized to nums[0] (the first element). Your task is to loop through the rest of the array and update max whenever you find a value that is larger than the current max.
Inside the loop, compare each element to max. If nums[i] is greater than max, update max to that value.
After the loop, print the result in this exact format:
Largest: 50Expected Output:
Largest: 50
Topics:
Arrays
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.