[FORTRAN] do-loop problem

  • Fortran
  • Thread starter Nicolaus
  • Start date
  • #1
73
0
How would I modify the program so it doesn't generate an output for integers that are multiples of 5? (e.g. if range was 1-20, then no lines would be printed for 5, 10, 15, 20.)

program squares
implicit none

integer*2 start, finish, i

! ----------------------------------------------Prompt and Input
print*, "Enter the range (two integers) ..."
read*, start, finish

! ----------------------------------------------Validation & Processing
if (start .GT. finish) then
print*, "Invalid: the start must be less than the end value!"
else if (start .LT. 0) then
print*, "Invalid: the range must not have negative values!"
else
do i = start, finish
write(*,*) i, sqrt(i*1.)
end do
end if
! ----------------------------------------------
end
 

Answers and Replies

  • #2
191
3


You could use an if statement that checks whether i % 5 == 0. The % operator is modulus and returns the remainder after division.
 

Related Threads on [FORTRAN] do-loop problem

  • Last Post
Replies
3
Views
1K
Replies
12
Views
1K
Replies
1
Views
8K
Replies
4
Views
1K
Replies
2
Views
2K
Replies
8
Views
13K
  • Last Post
Replies
10
Views
1K
Replies
1
Views
2K
Top