โ Back to Arrays
Question 99
Find the Smallest Element
Find the Smallest Element
An array called nums has already been created for you with the values {30, 10, 50, 20, 40}. Notice the values are not in order.
A variable called min has been initialized to nums[0] (the first element). Your task is to loop through the rest of the array and update min whenever you find a value that is smaller than the current min.
Inside the loop, compare each element to min. If nums[i] is less than min, update min to that value.
After the loop, print the result in this exact format:
Smallest: 10Expected Output:
Smallest: 10
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.