📜  fortran hello world (1)

📅  最后修改于: 2023-12-03 14:41:19.180000             🧑  作者: Mango

Fortran Hello World

Fortran is a high-level programming language that is particularly well-suited for scientific and engineering applications. A classic introduction to any programming language is the "Hello, world!" program. In Fortran, it looks like this:

program hello
  print *, "Hello, world!"
end program hello

Let's break this down line by line:

  • program hello: This declares the start of a new program called hello.
  • print *, "Hello, world!": This prints the text "Hello, world!" to the console. The * is a format specifier that indicates that the text should be printed without any formatting options.

To run this program, you'll need a Fortran compiler. One popular option is GFortran, which is part of the GCC suite of compilers. Once you have a compiler installed, save the hello world program to a file called hello.f90, and then compile and run it like this:

gfortran hello.f90 -o hello
./hello

This will compile the program into an executable called hello and then run it. You should see the message "Hello, world!" printed to the console.

Congratulations, you've written your first Fortran program! While it may seem simple, this is the foundation for building more complex programs in Fortran.


Conclusion

Fortran is a powerful language that has played a significant role in scientific and engineering computing for decades. While it can seem archaic compared to more modern languages, it remains popular due to its efficiency and ability to handle complex mathematical operations. The "Hello, world!" program is just the beginning - by learning Fortran, you open yourself up to a whole world of possibilities.