Learn Fortran - 10 Code Examples & CST Typing Practice Test
Fortran (Formula Translation) is a high-level, compiled programming language designed for numeric computation, scientific computing, and engineering applications. Known for its efficiency in numerical calculations, Fortran has been a standard in scientific computing for over 60 years.
Learn FORTRAN with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
Fortran Counter and Theme Toggle
program Counter
integer :: count = 0
logical :: isDark = .false.
print *, 'Counter:', count
print *, 'Theme:', merge('Dark','Light',isDark)
! Increment counter
count = count + 1
print *, 'Counter:', count
! Toggle theme
isDark = .not. isDark
print *, 'Theme:', merge('Dark','Light',isDark)
! Decrement counter
count = count - 1
print *, 'Counter:', count
! Reset counter
count = 0
print *, 'Counter:', count
end program Counter
Demonstrates a simple counter with theme toggling using Fortran variables and console output.
Fortran Simple Addition
program Addition
integer :: a = 10
integer :: b = 20
integer :: sum
sum = a + b
print *, 'Sum:', sum
end program Addition
Adds two numbers and prints the result.
Fortran Factorial
program Factorial
integer :: fact = 1
integer :: i
for i = 1, 5
fact = fact * i
end for
print *, 'Factorial:', fact
end program Factorial
Calculates factorial of 5 using a loop.
Fortran Fibonacci Sequence
program Fibonacci
integer :: fib0 = 0, fib1 = 1, next, i
print *, fib0
print *, fib1
do i = 3, 10
next = fib0 + fib1
print *, next
fib0 = fib1
fib1 = next
end do
end program Fibonacci
Generates first 10 Fibonacci numbers.
Fortran Max of Two Numbers
program MaxNumber
integer :: a = 15, b = 25, max
if (a > b) then
max = a
else
max = b
end if
print *, 'Max:', max
end program MaxNumber
Finds the maximum of two numbers.
Fortran Array Sum
program ArraySum
integer, dimension(5) :: nums = (/1,2,3,4,5/)
integer :: sum = 0, i
do i = 1, 5
sum = sum + nums(i)
end do
print *, 'Sum:', sum
end program ArraySum
Sums elements of an array.
Fortran Even Numbers Filter
program EvenFilter
integer, dimension(5) :: nums = (/1,2,3,4,5/)
integer :: i
do i = 1, 5
if (mod(nums(i),2) == 0) then
print *, 'Even:', nums(i)
end if
end do
end program EvenFilter
Prints even numbers from an array.
Fortran Conditional Counter Increment
program ConditionalIncrement
integer :: count = 3
if (count < 5) then
count = count + 1
end if
print *, 'Count:', count
end program ConditionalIncrement
Increment counter only if less than 5.
Fortran Resettable Counter
program ResettableCounter
integer :: count = 0
count = count + 1
count = count + 1
count = count + 1
print *, 'Count:', count
count = 0
print *, 'Count after reset:', count
end program ResettableCounter
Counter that increments and can be reset.
Fortran Theme Toggle Only
program ThemeToggle
logical :: isDark = .false.
print *, 'Theme:', merge('Dark','Light',isDark)
isDark = .not. isDark
print *, 'Theme:', merge('Dark','Light',isDark)
isDark = .not. isDark
print *, 'Theme:', merge('Dark','Light',isDark)
end program ThemeToggle
Toggles theme multiple times.
Frequently Asked Questions about Fortran
What is Fortran?
Fortran (Formula Translation) is a high-level, compiled programming language designed for numeric computation, scientific computing, and engineering applications. Known for its efficiency in numerical calculations, Fortran has been a standard in scientific computing for over 60 years.
What are the primary use cases for Fortran?
Scientific simulations. Numerical and matrix computations. High-performance computing. Weather & climate modeling. Finite element analysis. Computational physics & chemistry
What are the strengths of Fortran?
High computational performance. Mature ecosystem in scientific computing. Efficient memory and vectorized operations. Widely supported in HPC systems. Legacy codebases in critical scientific domains
What are the limitations of Fortran?
Primarily numerical, not general-purpose. Older syntax can be verbose. Limited libraries for modern tasks outside science. Cross-platform GUIs are weak. Complex parallel programming setup
How can I practice Fortran typing speed?
CodeSpeedTest offers 10+ real Fortran code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.