Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

second smallest number

how would i go about setting up a loop to find the second smallest number out of 8 numbers

Comments

  • tom_swtom_sw Member Posts: 828
    : how would i go about setting up a loop to find the second smallest number out of 8 numbers
    :
    I think somehting like this would do it.
    [code]
    create array of numbers - ary[8] and fill it appropriately
    set smallest = ary[0]
    set nextsmall = ary[1]
    if (smallest > nextsmall) swap (smallest, nextsmall)

    loop through ary[2-7]
    if ary[x] < nextsmall swap
    if nextsmall < smallest swap

    done
    [/code]
Sign In or Register to comment.