Checking if all elements in an array are equal

  • Thread starter Thread starter jimmy
  • Start date Start date
J

jimmy

Hi,

I have an array of type integer which i now want to sort through to
find out if all of the elements are equal to one another. I have code
that finds the lowest element in the array however i am struggling to
find a way to see if they are all equal.

Thanks in advance for any help

James
 
jimmy said:
Hi,

I have an array of type integer which i now want to sort through to
find out if all of the elements are equal to one another. I have code
that finds the lowest element in the array however i am struggling to
find a way to see if they are all equal.

Thanks in advance for any help

James

Solution to homework =

Loop thru the array comparing the element to the first element. If it is
not equal then the test fails.

........
 
James:

Consider the code you "have" to find the lowest value (I assume is what you
meant). How did you accomplish that? Did you check the first value and
then compare it to the next one to see if it was higher or lower? So if you
want to find out if they are equal what might you do instead?
 
Back
Top