Notepad/Obsidian-Notepad/enter/Coding Tips (Classical)/Terminal Tips/Languages/Fortran.md

36 lines
1.0 KiB
Markdown

Fortran stands for **For**mula **Tran**slating System - a programming language developed in 1857 at IBM.
program hello_world.f90
```
program first
implicit none
! write 'Hello World!' to stdout
write(*,*)"Hello world!"
end program first
```
compile and run with:
```
$ gfortran hello_world.f90 -o hello_world
$ ./hello_world
```
All code taked place between the program first and end program first statements, where first is the nmae given to the program. The `!` indicates a comment and the `write(*,*)` instructs the computer to write the statement Hello World to the screen, indicated by the first asterisk using free-format, the second asterisk. The implicit none if a very important statement as well.
```
program temperature
implicit none
! declare variables
real :: DegC, DegF
write(*,*)"Please type in temp in Celcius"
! the read statement read input from
! keyboard and stores it invariable DegC
DegF = (9./5)*DegC + 32.
! the write statement accepts multiple
! strings or variables, separated
! by commons
```