Fortran Can You Loop Numbers and Write an Output File in Fortran?

  • Thread starter Thread starter ƒ(x) → ∞
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
Looping through a set of numbers in Fortran can be accomplished using nested loops. For example, to print numbers from 1 to 52 repeatedly, a simple nested loop structure can be implemented. The outer loop controls the number of times the sequence is repeated, while the inner loop iterates through the numbers 1 to 52. Regarding writing to a file in Fortran, it is recommended to parse each character in a line, modify them as needed, and then concatenate them into a single string. This string can then be written to the file in one operation, rather than writing each character individually, which is more efficient.
ƒ(x) → ∞
Messages
24
Reaction score
0
Is it possible to loop a set of numbers?

For example I wish to run a set of number 1,2,3,4,5...52 but when we get to 52 I wish to go back to 1 and start looping again.

How do write an output file in Fortran?

I have opened a file and moved each character so that each letter has moved for example d to e...x to y... How could I write this new series of characters to a file
 
Technology news on Phys.org
Not sure what you mean by "run" a set of numbers. If you just wish to print them, then something easy enough like this should work:
Code:
do i=1,n !-- number of times you wish you loop
 do j=1,52
    write(6,*) j
 end do
end do

As far as the second question, you might be best parsing each character in a line, and then concatenating them all to one text string and writing that entire line to file (rather than character by character).
 
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
8
Views
4K
Replies
3
Views
3K
Replies
6
Views
2K
Replies
8
Views
2K
Replies
5
Views
2K
Replies
6
Views
3K
Replies
1
Views
3K
Replies
19
Views
6K
Back
Top