Fizz Buzz in Fortran

Published on 01 October 2020 (Updated: 15 October 2025)

Welcome to the Fizz Buzz in Fortran page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

program fizzbuzz
   implicit none
   integer, parameter :: n = 100
   integer :: i

   do i = 1, n
      write(*,'(A)') fizzbuzz_string(i)
   end do

contains

   pure function fizzbuzz_string(x) result(str)
      integer, intent(in) :: x
      character(len=8) :: str

      str = ''

      if (mod(x,3) == 0) str = 'Fizz'
      if (mod(x,5) == 0) str = trim(str)//'Buzz'
      if (len_trim(str) == 0) write(str,'(I0)') x
   end function fizzbuzz_string

end program fizzbuzz

Fizz Buzz in Fortran was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.