find 5th smallest element from array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anu401
    New Member
    • Nov 2009
    • 9

    find 5th smallest element from array?

    how to find out the 5 th smallest element from the following array?
    10,20,30,40,50, 60,70,80,90,100 .
    no need of program for me i need only the sum
    i need only that mechanism....
    i need how the loop works and how that numbers are used in loops.........p lease help
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Sort the array.

    Then pick the 5th element of the sorted array.

    Comment

    • anu401
      New Member
      • Nov 2009
      • 9

      #3
      already it looks like sorted element how to choose smallest element i cant get the answer
      i dont know how the loop works

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        What is this loop that you are referring to? Do you have the code for it?

        Comment

        • Oralloy
          Recognized Expert Contributor
          • Jun 2010
          • 988

          #5
          Likely you simply want the fifth array element, for example "a[4]", if you'd sorted the elements into array "a".

          Of course, if there are less than five elements in your array, you'll have to fail appropriately.

          Still, if you post code, we might be able to help you better.

          Comment

          • santechselva
            New Member
            • May 2010
            • 8

            #6
            for(i=0;i<10;i+ +)
            {
            for(j=1+1;j<10; j++)
            {
            if(a[i]>a[j])
            {
            a[i]=k;
            a[i]=a[j];
            a[j]=k;
            }
            }
            }

            THIS IS USED FOR SORTING OF 10 NUMBERS IN ASCENDING ORDER
            MODIFY YOUR PROGRAM BY PRINTING THE FIFTH ELEMENT

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #7
              Change 7th line from
              Code:
              a[i] = k;
              to
              Code:
              k = a[i];
              Please use CODE tags.

              Comment

              Working...