first commit
This commit is contained in:
37
FizzBuzz/Fortran/fizzbuzz.f90
Normal file
37
FizzBuzz/Fortran/fizzbuzz.f90
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
Reference in New Issue
Block a user