How to swap number in the fortran memory?

  • Context: Fortran 
  • Thread starter Thread starter dadidudada
  • Start date Start date
  • Tags Tags
    Fortran Memory
Click For Summary

Discussion Overview

The discussion revolves around swapping numbers in Fortran memory, particularly within a loop structure. Participants explore methods for swapping values and arranging numbers in ascending order, focusing on practical coding techniques and logic implementation.

Discussion Character

  • Technical explanation
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant asks how to swap two numbers in Fortran memory using a do loop.
  • Another participant suggests a straightforward method using a temporary variable to facilitate the swap.
  • A different participant expresses confusion about arranging a set of numbers in ascending order.
  • One response proposes a method for sorting by repeatedly swapping adjacent elements if they are out of order, suggesting the use of a flag to optimize the process.
  • A later reply acknowledges the sorting method as a solution, crediting the contributor for the help.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method for swapping numbers, but there is agreement on the general approach to sorting numbers through repeated swaps.

Contextual Notes

Some participants express uncertainty about the implementation details, such as the specific structure of the do loop and the handling of multiple numbers for sorting.

Who May Find This Useful

Individuals new to Fortran programming, particularly those interested in memory manipulation and sorting algorithms.

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...
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 17 ·
Replies
17
Views
6K