Printing certain values from a DO loop in Fortran

AI Thread Summary
To print every 100th value of the loop variable 'i' in a Fortran program, the use of the modulus operator is effective. The condition `if (mod(i,100) .eq. 0)` correctly identifies values of 'i' that are multiples of 100, including 100, 200, 300, and so on, up to 20000. This ensures that the program will print the desired values at each iteration where 'i' meets the condition, confirming that it works as intended.
johnwalton84
Messages
16
Reaction score
0
I've written a program in Fortran which has a do loop of the form

do i=0,20000

(operations)

end do


I want the program to print the values of the do loop, but only want it to print every 100th value of i (i.e. 100,200,300,400...20000), can anyone suggest a way to do this?
 
Computer science news on Phys.org
if (mod(i,100) .eq. 0) then
print stuff
endif
 
Would that not only work for i=100 though? If i is 200 then the mod(200,100) wouldn't be 0 so it wouldn't print?
 
Obviously not cos its worked :smile:

Thanks for that imabug!
 
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...

Similar threads

Replies
8
Views
1K
Replies
13
Views
2K
Replies
5
Views
1K
Replies
8
Views
4K
Replies
7
Views
4K
Replies
19
Views
2K
Replies
9
Views
3K
Back
Top