EVEN-ODD
!Program name: EVEN-ODD
!Routine
to determine whether an input number is even or odd
integer :: n,nh
Print *, "input n: "
Read *, n
nh=n/2
!
If you type 1, 3, 5, (odd number), the result is rounded to 0, 1, 2
!
If you type 0, 2, 4, (even number), the result is rounded to 0, 1, 2
print *, nh
if (2*nh==n) then
print *, 2*nh,
"even"
else
print *, 2*nh, "odd"
!
If n=1, nh=0, 2*nh=0, 1≠0, odd
!
If n=2, nh=1, 2*nh=2, 2 = 2, even
!
If n=3, nh=1, 2*nh=2, 3 ≠ 2, odd
!
If n=4, nh=2, 2*nh=4, 4 = 4, even
end if
stop
Comentários
Postar um comentário