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 had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

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