CJCoding With Joseph
15free / daySign inCreate account

Check if All Elements Are the Same

An array called nums has already been created for you with the values {10, 10, 10, 10, 10}.

Your task is to check whether every element in the array has the same value. If they are all the same, print "All same". If any element is different, print "Not all same".

The approach is to compare each element to the first element (nums[0]). If you find any element that doesn't match, the array is not all the same.

Since every element in this array is 10, the expected output is exactly what is shown in Expected Output.

Expected Output:

All same

= newline. No newline after the last line.

Hints4 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.