Fortran How to swap number in the fortran memory?

  • Thread starter Thread starter dadidudada
  • Start date Start date
  • Tags Tags
    Fortran Memory
AI Thread Summary
To swap numbers in Fortran memory, one effective method is to use a temporary variable. For example, to swap the values of x(1) and x(2), assign x(1) to a temporary variable, then set x(1) to x(2), and finally assign the temporary variable to x(2). For sorting an array of numbers, a common approach is to implement a bubble sort algorithm. This involves iterating through the list, comparing adjacent elements, and swapping them if they are in the wrong order. A flag can be used to optimize the process by stopping the loop if no swaps occur during a complete pass through the array. The discussion concludes with a successful resolution to the initial query.
dadidudada
Messages
6
Reaction score
0
how to swap number in the fortran memory??

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...
 
Technology news on Phys.org


Why would you not use;

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

?
 


ok I am completely blank..
if i have to arrange these number(10,4,1)into ascending order..
what should i do..
 
Last edited:


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.
 


cmb said:
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...
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
25
Views
3K
Replies
2
Views
1K
Replies
3
Views
2K
Replies
8
Views
4K
Replies
19
Views
5K
Replies
4
Views
2K
Replies
3
Views
2K
Replies
17
Views
5K
Back
Top