1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

4桁までしかできない FizzBuzz

Last updated at Posted at 2014-05-22

Fortran でも色々なパターンは出尽くしているので、短めで奇をてらった方法を考えること1時間w 文字列のはみだしを利用。

    program FizzBuzz
      implicit none
      character(len=4), parameter :: c3(0:2) = ['Fizz','',''], &
                                     c5(0:4) = ['Buzz','','','','']
      character(len=16) :: buf  
      integer :: i, n = 10000 ! max 10000
      do i = 1, n
        write(buf, '(2a4, a4, i4)') c3(mod(i, 3)), c5(mod(i, 5)), '    ', i
        write(*, '(a8)', advance = 'no'), adjustl(buf)
      end do
    end program FizzBuzz

FizzBuzz.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?