CJCoding With Joseph
15free / daySign inCreate account

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 the exact format shown in Expected Output.

Expected Output:

Smallest: 10

= newline. No newline after the last line.

Hints2 available
Topics:
Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.