Lecture_notes_summary1

Lecture_notes_summary1 - Chapter 1 The Program Algorithm 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 1 The Program Algorithm 1 First example Our first example consists of the following algorithm: 1: i ← 2 2: j ← 2 3: k ← i + j 4: PRINT k FIRST EXAMPLE PROGRAM FIRST EXAMPLE INTEGER : : i , j , k i =2 j =2 k=i+j WRITE ( ∗ , ∗ ) k END FIRST EXAMPLE Save as FIRST EXAMPLE.f95 FIRST EXAMPLE Commands and Output g f o r t r a n FIRST EXAMPLE . f 9 5 . / a . out 4 FIRST EXAMPLE Commands and Output g f o r t r a n FIRST EXAMPLE . f95 −o FIRST EXAMPLE FORTRAN . /FIRST EXAMPLE FORTRAN 4 3 MAT 5939-03 1.1 Pierre Garreau Description of a program • Fortran Programs all start with PROGRAM PROGRAM NAME and end with END PROGRAM PROGRAM NAME • INTEGER :: i,j,k declares i,j, and k as integers. • i=2,j=2 assign the value of 2 to i and j. • k=i+j adds i and j and assigns the value of k. • WRITE (∗,∗) k prints the value of k to the screen. 1.2 Compiling and running • Save file with a .f90 ending to signify that it is a fortran 90 program. • Download a compiler. You may find a compiler at http://gcc.gnu.org/wiki/GFortranBinaries. • gfortran FIRST EXAMPLE.f90 -0 FIRST EXAMPLE compiles and generates an executable file which can be launched with the command ./ FIRST EXAMPLE . 1.3 Other Formatting • Anything after the ! is considered a comment. • & can be used to break up lines by putting & at the end of one line and the start of the next line. Add this to FIRST EXAMPLE.f95 ! This i s a comment and i s not e x e c u t e d PRINT ∗ , ’We can break up l o n g l i n e s & &l i k e t h i s t& &o s h o r t e n l i n e s and make i t e a s i e r t o r e a d ’ OUTPUT: We can break up long lines like this to shorten lines and make it easier to read Fall 11 - September 4, 2011 4 ...
View Full Document

This note was uploaded on 01/15/2012 for the course MAT 5939 taught by Professor Garreau during the Fall '11 term at FSU.

Page1 / 2

Lecture_notes_summary1 - Chapter 1 The Program Algorithm 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online