Checking if all elements in an array are equal

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jimmy

    #1

    Checking if all elements in an array are equal

    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

  • Lloyd Sheen

    #2
    Re: Checking if all elements in an array are equal


    "jimmy" <james.herringt on@tiscali.co.u kwrote in message
    news:1175944475 .920862.101020@ d57g2000hsg.goo glegroups.com.. .
    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.

    ........

    Comment

    • Tom Leylan

      #3
      Re: Checking if all elements in an array are equal

      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?

      "jimmy" <james.herringt on@tiscali.co.u kwrote in message
      news:1175944475 .920862.101020@ d57g2000hsg.goo glegroups.com.. .
      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
      >

      Comment

      Working...