PDA

View Full Version : how to swap number in the fortran memory??


dadidudada
Dec13-11, 10:18 AM
hello..
im new to fortran so how i swap number in do loop
first the tracing is like this:

x(1)=3
x(2)=8

then, how to i can swap the number in x(1) and x(2)

can anyone help me
please...

cmb
Dec13-11, 10:46 AM
Why would you not use;

a=x(1)
x(1)=x(2)
x(2)=a

?

dadidudada
Dec13-11, 10:48 AM
ok im completely blank..
if i have to arrange these number(10,4,1)into ascending order..
what should i do..

cmb
Dec13-11, 06:04 PM
Run through each number (to n-1) in the list (of n numbers) and swap over any where x(a) > x(a+1). Repeat. Set up a flag so you can stop if none are swapped during a repeat.

dadidudada
Dec13-11, 10:01 PM
Run through each number (to n-1) in the list (of n numbers) and swap over any where x(a) > x(a+1). Repeat. Set up a flag so you can stop if none are swapped during a repeat.

thanks man!!!its solved..
credit to cmb...