c++ script help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #16
    Originally posted by zerobinary
    4/2 + 4/2-1 /2
    because of order of operation so is the ((4/2+4/2)-1)/2
    which is 2+2-1 which is three then divided by 2.
    but that is the first number plus second /2.
    not second number +the third one??????
    If there are four (4) numbers to be considered, take the 4/2 and 4/2-1, which are
    the 2nd and 1st numbers and take the average of them. Remember C and C++
    start counting array elements from zero: the 0th, 1st, 2nd, 3rd, 4th, 5th element etc.

    kind regards,

    Jos

    Comment

    • zerobinary
      New Member
      • Aug 2007
      • 23

      #17
      so is the fifth number divided by 2 but rounded up the decimal.
      so is 5/2 +5/2-1 then divided by 2
      so is 2.5 + 1.5/2
      but since they rounded up it is 3+2 /2 right?????

      Comment

      • zerobinary
        New Member
        • Aug 2007
        • 23

        #18
        plz come back and help.
        I need ur help plz.

        Comment

        • zerobinary
          New Member
          • Aug 2007
          • 23

          #19
          or is it 4/2+1 and 4/2-1+1 then divided by two.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #20
            Originally posted by zerobinary
            or is it 4/2+1 and 4/2-1+1 then divided by two.
            What are you juggling? Here's another example:

            0:10
            1:20
            2:30
            3:40
            4:60

            The number left of the colon is the index of the number, right of the colon is
            the number itself. This array has 5 elements, so 5/2 == 2 so that median is
            found at index number 2, which is 30.

            For an even number of elements:

            0:10
            1:20
            2:30
            3:40

            There are four elements so take the average of the numbers at indexes 4/2
            and 4/2-1, which are index values 2 and 1 so take the average of 30 and 20
            which makes (30+20)/2 == 25.

            In general: if n (the number of elements in the array) is odd, take the
            element at index value n/2; if n is even take the average of the two numbers
            at index positions n/2 and n/2-1. Of course the numbers in the array need
            to be sorted, either ascending or descending.

            kind regards,

            Jos

            Comment

            • zerobinary
              New Member
              • Aug 2007
              • 23

              #21
              I get it now thx
              for ur great help

              Comment

              Working...