fortran
- User
fortran
- Assistant
fortran
Fortran (short for Formula Translation) is one of the oldest high-level programming languages, primarily designed for numerical and scientific computing. Developed in the 1950s by IBM, Fortran has evolved through numerous standards, with the latest being Fortran 2018. It remains in use today, especially in areas like computational fluid dynamics, finite element analysis, weather modeling, and other high-performance computing applications.
Here's a simple Fortran program that computes the factorial of a number using a recursive function:
program factorial_example
implicit none
integer :: number, result
print *, 'Enter a number:'
read *, number
if (number < 0) then
print *, 'Factorial is not defined for negative numbers.'
else
result = factorial(number)
print *, 'Factorial of ', number, ' is ', result
endif
end program factorial_example
recursive function factorial(n) result(fact)
integer, intent(in) :: n
integer :: fact
if (n == 0) then
fact = 1
else
fact = n * factorial(n - 1)
endif
end function factorial
Explanation:
factorial function.factorial function computes the factorial of a given number recursively.Choose a Compiler:
Set Up the Environment:
Write Your First Program:
.f90 extension (Fortran 90/95/2003/2008/2018).Compile and Run:
gfortran -o factorial factorial_example.f90
./factorial
Books:
Online Tutorials:
Documentation:
Forums:
Mailing Lists:
While Fortran may not be as widely used as some modern languages like Python or C++, its unparalleled performance in numerical and scientific computing ensures its continued relevance. Whether you're maintaining legacy systems or developing new high-performance applications, Fortran remains a powerful tool in the programmer's toolkit.
If you have specific questions about Fortran or need assistance with a particular aspect, feel free to ask!
Not yet included in a published release.