Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
  1. Home
  2. /
  3. Learn
  4. /
  5. Fortran

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.

View all 10 Fortran code examples →
Fortran Counter and Theme ToggleFortran Simple AdditionFortran FactorialFortran Fibonacci SequenceFortran Max of Two NumbersFortran Array SumFortran Even Numbers FilterFortran Conditional Counter IncrementFortran Resettable CounterFortran Theme Toggle Only

Learn FORTRAN with Real Code Examples

Updated Nov 20, 2025

Explain

Fortran excels at high-performance numerical computation and array processing.

It supports modular programming, procedures, and modern object-oriented features in newer standards.

Commonly used in scientific simulations, weather modeling, computational physics, and engineering calculations.

Core Features

Modules and subroutines

Array operations and intrinsic functions

Derived data types

Control structures (loops, conditionals)

I/O facilities for formatted/unformatted data

Basic Concepts Overview

Variables, constants, and types

Control structures (if, do, select case)

Subroutines and functions

Modules and derived types

Arrays and intrinsic operations

Project Structure

source.f90 files

modules/

libraries/

tests/

executables/

Building Workflow

Write .f90 or .f95 source file

Compile with Fortran compiler

Link libraries if needed

Run executable

Debug using gdb or compiler flags

Difficulty Use Cases

Beginner: simple arithmetic & loops

Intermediate: subroutines and modules

Advanced: parallel programming & large-scale simulations

Expert: HPC code optimization, legacy code maintenance

Comparisons

Faster than interpreted languages for numeric computation

Better array handling than C in some cases

Less general-purpose than Python or Java

Strong legacy presence in HPC vs newer languages

Syntax can be verbose compared to modern languages

Versioning Timeline

1957 - Fortran I released

1960 - Fortran II

1978 - Fortran 77 standard

1990 - Fortran 90 (modern features)

2003-2025 - Fortran 2003, 2008, 2018 standards for OOP and parallelism

Glossary

Module: container for functions/subroutines

Subroutine: procedure with no return value

Function: procedure returning value

Intrinsic function: built-in Fortran function

Array: collection of same-type elements

Installation Setup

Install Fortran compiler (gfortran, Intel Fortran, PGI)

Verify compiler in terminal

Set PATH for environment

Write sample program (Hello World)

Compile and run program

Environment Setup

Install Fortran compiler

Set PATH for compiler

Install libraries (BLAS, LAPACK, MPI)

Verify compilation

Run test programs

Config Files

Makefile for builds

Module definition files

Compiler config flags

HPC batch scripts

Library dependencies (e.g., BLAS/LAPACK)

Cli Commands

gfortran source.f90 -o executable

ifort source.f90 -o executable

mpif90 source.f90 -o executable

./executable

gdb ./executable

Internationalization

Support for UTF-8 strings in newer compilers

Locale-aware formatting for numbers

No GUI localization built-in

External visualization supports internationalization

Numeric precision consistent worldwide

Accessibility

Documentation via Fortran standards

Online tutorials & examples

HPC user forums

University courses

Code examples for legacy systems

Ui Styling

Minimal - primarily console I/O

Visualization via external tools (Python, MATLAB, gnuplot)

Tk or GUI libraries possible but uncommon

Focus is numerical output

Plotting handled outside Fortran

State Management

Variables in memory

Arrays for temporary storage

Modules maintain global state

Parallel threads may have private/shared state

Use synchronization primitives in MPI/OpenMP

Data Management

Arrays and matrices

Formatted and unformatted files

Structured derived types

External libraries for scientific data

Input/output streams

Architecture

Compiled language

Supports procedural & object-oriented paradigms

Array-oriented design

Parallel processing via OpenMP/MPI

Modules for namespace management

Rendering Model

Source code compiled into machine code

Executable runs on CPU

Modules provide namespace and reusability

Intrinsic functions optimized by compiler

Parallel loops distributed on threads/processors

Architectural Patterns

Procedural programming

Modular programming via modules

Array and matrix-oriented design

Parallel execution (OpenMP/MPI)

Scientific computation pipelines

Real World Architectures

Climate & weather modeling

Computational physics

Aerospace simulations

Finite element analysis

High-performance numerical pipelines

Design Principles

Optimize numerical computations

Array-oriented design

Efficient compiled execution

Backward compatibility

Support for parallelism

Scalability Guide

Vectorize loops

Use parallelism with OpenMP/MPI

Modularize code for HPC clusters

Minimize I/O bottlenecks

Leverage optimized libraries (BLAS/LAPACK)

Migration Guide

Convert legacy Fortran 77 to Fortran 90/2003

Modularize old code into modules

Use modern parallel libraries

Replace fixed-format I/O with free-format

Integrate with Python/C for modern pipelines

Performance Notes

Use array operations instead of loops

Enable compiler optimizations

Parallelize with OpenMP or MPI

Avoid unnecessary I/O in loops

Use appropriate precision types

Security Notes

Validate inputs for numerical stability

Avoid buffer overflows in I/O

Check for integer overflows

Ensure safe memory allocation

Sanitize external data for simulations

Monitoring Analytics

Print/log for debugging

Compiler warnings

Profiling with gprof or Intel VTune

Performance benchmarking

Regression tests

Code Quality

Use modules and subroutines

Avoid global variables

Document inputs/outputs

Use intrinsic functions

Validate array bounds

Practical Examples

Matrix multiplication

Numerical integration

Weather simulation module

Finite element analysis

Vectorized linear algebra

Troubleshooting

Check compiler flags

Verify array bounds

Ensure correct module use

Debug with print statements or gdb

Check for floating-point errors

Testing Guide

Unit test with assert statements

Check array bounds and outputs

Use regression tests for scientific calculations

Compare against analytical solutions

Validate parallel execution correctness

Deployment Options

Compile executables

Deploy in HPC clusters

Embed in pipelines for simulations

Link with scientific libraries

Package as modules for reuse

Tools Ecosystem

gfortran (GNU Fortran)

Intel Fortran Compiler

PGI Fortran

OpenMP/MPI libraries

Fortran IDEs (Photran, Code::Blocks)

Integrations

C/C++ via ISO_C_BINDING

Python via f2py

MPI/OpenMP parallel libraries

NetCDF/HDF5 for scientific data

Visualization tools like Matplotlib (via Python interface)

Productivity Tips

Use compiler optimizations

Vectorize arrays

Parallelize loops

Reuse modules

Automate build & testing

Challenges

Matrix multiplication

Numerical integration

Solve differential equations

Parallelize a physics simulation

Optimize legacy Fortran code

Learning Path

Learn Fortran syntax and variables

Master arrays and intrinsic functions

Understand modules and subroutines

Learn file I/O and formatted output

Practice numerical problem solving

Skill Improvement Plan

Week 1: Variables, loops, conditionals

Week 2: Subroutines, modules, functions

Week 3: Arrays, intrinsic functions, I/O

Week 4: Parallel programming (OpenMP/MPI)

Interview Questions

Explain the difference between Fortran 77 and Fortran 90.

How do you pass arrays to subroutines?

What is the purpose of modules?

How do you parallelize loops?

What are intrinsic functions in Fortran?

Cheat Sheet

program name ... end program name

subroutine subname(args) ... end subroutine

do i=1,n ... end do

if (condition) then ... end if

print *, 'Hello World'

Books

Modern Fortran Explained

Introduction to Fortran 90/95

Numerical Recipes in Fortran

Tutorials

Fortran Tutorial by TutorialsPoint

Modern Fortran Guide

HPC Fortran Programming Tutorials

Official Docs

ISO Fortran Standards

Fortran-lang.org

Intel Fortran Documentation

Community Links

Fortran-lang.org

StackOverflow Fortran tag

GitHub Fortran repositories

Community Support

StackOverflow Fortran tag

Fortran-lang.org community

GitHub HPC & Fortran projects

HPC forums

University research labs

Monetization

HPC software development

Scientific consulting

Engineering simulations

Aerospace & defense simulations

Energy modeling services

Future Roadmap

Better parallelism support

Modernization of standards

Integration with Python/Julia

Enhanced compiler optimizations

Continued HPC relevance

When Not To Use

Web development

Mobile applications

Modern GUI applications

Non-numeric business apps

Rapid prototyping outside science

Final Summary

Fortran is a high-performance language for scientific computing and numerical simulations.

It excels in array-based computation, HPC, and legacy scientific codebases.

Modern standards support modular and object-oriented programming.

Still widely used in engineering, physics, climate modeling, and computational chemistry.

Faq

Is Fortran still relevant?

Yes - especially in scientific computing and HPC.

Can Fortran do object-oriented programming?

Yes - modern standards (Fortran 90/2003/2008) support OOP.

Is Fortran fast?

Yes - excellent for numerical and array operations.

Can I integrate Fortran with Python?

Yes - using f2py or C bindings.

Code Sample Descriptions

1

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.

Let’s Try →
2

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.

Let’s Try →
3

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.

Let’s Try →
4

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.

Let’s Try →
5

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.

Let’s Try →
6

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.

Let’s Try →
7

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.

Let’s Try →
8

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.

Let’s Try →
9

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.

Let’s Try →
10

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.

Let’s Try →

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.

Learn Other Programming Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlinPartiqlHaskellElixirFsharpView all languages →
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.