Re: ordinate a sequences of number



gambato@xxxxxxxxxxxx wrote:
 ....I want to organize all my numbers so that the first is the
smallest one and the last is the bigger one.

Yes. This is called "sorting". You'll find a vast supply of different algorithms for doing that, under that name.


why do you say that I haven't yet read the elements from 2 to n?
I thought: I read n-1 elements and I compare the first elements with
successive one (j=2,n) and so on the second one with j=3,n, etc....

That may be what you _thought_. However, this is the code you wrote:

      do 10  i=1, (n-1)
         read (11,*) fvx(i)
         minx= fvx(i)
         do 20  j=(i+1),n
            if (fvx(j) .lt. minx) then
               min= fvx(j)
            end if
c               write(*,*) min
 20            continue
         pos(i)=min
 10       continue

Look at what each line does, in turn, and think about what happens when the computer executes it.

The first line sets up a loop of i=1 to n-1. It also sets i=1 for the first iteration through the loop.

On the first pass through the loop, the second line reads in fvx(1).

On the first pass through the loop, the third line sets minx = fvx(1).

On the first pass through the loop, the fourth line starts a loop over j=2 to n.

And so the computer starts running that loop after you've only read in one of the fvx values. All of the fvx values from 2 to n haven't been defined yet, because you haven't read them in yet.

It is always good practice to mentally step through the lines of your program like this to make sure that what you think should happen is what will actually happen.

- Brooks


-- The "bmoses-nospam" address is valid; no unmunging needed. .