How to resolve the algorithm FizzBuzz step by step in the Fortran programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm FizzBuzz step by step in the Fortran programming language
Table of Contents
Problem Statement
Write a program that prints the integers from 1 to 100 (inclusive).
But:
The FizzBuzz problem was presented as the lowest level of comprehension required to illustrate adequacy.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm FizzBuzz step by step in the Fortran programming language
Source code in the fortran programming language
program fizzbuzz_if
integer :: i
do i = 1, 100
if (mod(i,15) == 0) then; print *, 'FizzBuzz'
else if (mod(i,3) == 0) then; print *, 'Fizz'
else if (mod(i,5) == 0) then; print *, 'Buzz'
else; print *, i
end if
end do
end program fizzbuzz_if
program FizzBuzz
implicit none
integer :: i = 1
do i = 1, 100
if (Mod(i,3) == 0)write(*,"(A)",advance='no') "Fizz"
if (Mod(i,5) == 0)write(*,"(A)",advance='no') "Buzz"
if (Mod(i,3) /= 0 .and. Mod(i,5) /=0 )write(*,"(I3)",advance='no') i
print *, ""
end do
end program FizzBuzz
program fizzbuzz_select
integer :: i
do i = 1, 100
select case (mod(i,15))
case 0; print *, 'FizzBuzz'
case 3,6,9,12; print *, 'Fizz'
case 5,10; print *, 'Buzz'
case default; print *, i
end select
end do
end program fizzbuzz_select
You may also check:How to resolve the algorithm Chat server step by step in the Groovy programming language
You may also check:How to resolve the algorithm Distributed programming step by step in the Erlang programming language
You may also check:How to resolve the algorithm Primes - allocate descendants to their ancestors step by step in the Nim programming language
You may also check:How to resolve the algorithm Symmetric difference step by step in the Ursala programming language
You may also check:How to resolve the algorithm Minesweeper game step by step in the PHP programming language