38 lines
826 B
Fortran
38 lines
826 B
Fortran
subroutine fizzbuzzsub(n)
|
|
implicit none
|
|
integer, intent(in) :: n
|
|
integer :: i
|
|
|
|
do i = 1, n
|
|
if ((modulo(i,3) == 0) .OR. (modulo(i,5) == 0)) then
|
|
if (mod(i,3)==0) then
|
|
write(*, "(a)", advance="no") "Fizz"
|
|
end if
|
|
if (mod(i,5)==0) then
|
|
write(*, "(a)", advance="no") "Buzz"
|
|
end if
|
|
else
|
|
write(*, "(i0)", advance="no") i
|
|
end if
|
|
print *,""
|
|
end do
|
|
|
|
|
|
|
|
end subroutine fizzbuzzsub
|
|
|
|
program fizzbuzz
|
|
implicit none
|
|
integer :: n
|
|
integer :: Reason
|
|
|
|
print *, "How many fizzbuzzes?: "
|
|
read (*,*,IOSTAT=Reason) n
|
|
|
|
if (Reason > 0) then
|
|
print *, "Invalid input"
|
|
else
|
|
call fizzbuzzsub(n)
|
|
end if
|
|
end program fizzbuzz
|