0% found this document useful (0 votes)
17 views1 page

Hello World2407

Uploaded by

xhynhjkmgg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Hello World2407

Uploaded by

xhynhjkmgg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Writing “Hello World” Program

A “Hello World” program is a computer program that prints to the screen the words “hello world”. It is
the simplest example of a program one can write and is often used to introduce students to a programming
language.

1. Open up a terminal window and creating a folder


Open up the terminal window (this can be found under accessories in the applications tab). Create a
directory/folder called “Introduction” by using the UNIX command mkdir (make directory)
mkdir Introduction
Now move to your folder Introduction using the UNIX command cd which changes directory
cd Introduction
Now check to see what directory you are in by typing
pwd
This checks the present working directory and should say Introduction as the last item in string.

2. Open an f90 file


Open up a blank file titled, for example, hello world.f90. Recall that all Fortran 90 files should have the
extension “.f90” I have named the program “hello world” but you can choose a different (but descriptive)
name. To do this, type the following:
emacs hello world.f90

3. Writing the program


Copy the three lines below into your blank file. Note that it does not matter if you put spaces before you
start typing or more than one space in between words. Also note that the name you gave the program on
the first and last lines must match. However, it does not have to match the name of the file itself but usually
it does.

program hello world


print *, "Hello World!"
end program hello world
The first and last lines tell the compiler where the program starts and ends. We will have these two lines
in all of our programs. In between is a line of code which prints (in the simplest possible way) the words
“Hello World!”. Whatever characters you want to print must be enclosed in double quotation marks.
Save your file.

4. Compiling
For this class we will use the gfortran compiler. Recall that a compiler is a computer program that translates
your source code in the fortran language to assembly or machine language for the purpose of making an
executable file. To compile your program use the command
gfortran hello world.f90
Note that this must be the name of the file you opened in #2. This will produce an executable that is called
“a.out”. After you have done this, if you type the UNIX command ls it will list the files you have in the
directory Introduction – you should have your source code and the a.out file.

5. Executing
To execute the executable a.out file type
./a.out
If you did everything carefully, then it should print Hello World! to the screen.

You might also like