136k views
5 votes
Write a do loop that prints the odd numbers from −3 to 15 to the screen. (Write just the do loop, no declarations or any other parts of the code are needed.) In Fortran please

1 Answer

5 votes

Final answer:

Use a do loop with a conditional statement inside to check for odd numbers between -3 and 15 in Fortran, then print those numbers.

Step-by-step explanation:

To write a do loop in Fortran that prints odd numbers from −3 to 15, you can use the following code snippet:

do i = -3, 15
if (mod(i, 2) /= 0) then
print *, i
end if
end do

The loop variable i starts at −3 and increments by 1 until it reaches 15. The conditional statement mod(i, 2) /= 0 checks if i is odd (modulus division by 2 does not yield zero). If the condition is true, it prints the odd number to the screen.

User Jfdimark
by
8.3k points