Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 2:BASIC FORTRAN Data Types INTEGER REAL COMPLEX CHARACTER LOGICAL.

Similar presentations


Presentation on theme: "CHAPTER 2:BASIC FORTRAN Data Types INTEGER REAL COMPLEX CHARACTER LOGICAL."— Presentation transcript:

1 CHAPTER 2:BASIC FORTRAN Data Types INTEGER REAL COMPLEX CHARACTER LOGICAL

2 -4 0 55 -55 INTEGERS A whole Number NO Commas or A Decimal Point 9,99 16.1

3 -4.3 -.03 +337.5 3.375E2 REALS Decimal Numbers Exponential Notation 9,99 16

4 Mass K_S_U R4U MASS Identifiers -Names used to identify - Begin with a letter -Max 30 characters R-U 4all

5 Variables associated with a memory locationVariable names are identifiersthe type of any variable used must be declared CHARACTER(n)::Name n:Length

6 INTEGER :: Student_ID REAL ::Age CHARACTER (LEN = 15) : : FirstName, LastName CHARACTER(15) : : FisrtName, LastName CHARACTER(15) : : FirstName, LastName*20, Initial*1

7 IMPLICIT NONE Statement undeclared identifier whose name begins with I, J, K, L, M, or N  integer All other will be types as real IMPLICIT NONE Every data MUST be defined!

8 2.3 Numeric Operations The following characters are used in FORTRAN as denoted: * multiplication -subtraction + addition /division ** exponentiation

9 When two constants or variables of the same type are combined  result has the same type Examples: 9/4 9.0/4.0

10 Mixed-Mode Expressions 1.0 / 4 »» 3.0 + 8 / 5 »» 3 + 8.0 / 5 »» 1.0 / 4.0 »» 0.25 3.0 + 1 »» 3.0 + 1.0 »» 4.0 3 + 8.0 / 5.0 »» 3 + 1.6 »» 3.0 + 1.6 »» 4.6 CHECK: (-4.0)**2 (-4.0)**2.0

11 Priority Rules Exponentiations are performed first; Multiplications and divisions are performed next, in the appearance order. The additions and subtractions are performed last, in the appearance order. Parentheses can be used to modify the standard order of evaluation.

12 EXAMPLES 2 ** 3 ** 2 = 2 ** 9 = 512 10 – 8 – 2 = 2 -2 = 0 10 / 5 * 2 = 2 * 2 = 4 2 + 4 / 2 = 2 + 2 = 4 2 + 4 ** 2 / 2 = 2 + 16 / 2 = 2+ 8 = 10

13 (5 * (11 – 5) ** 2) * 4 + 9 = (5 * 6 ** 2) * 4 + 9 = 180 * 4 + 9 = 720 + 9 = 729

14 Lab Assessment: Q.1: Calculate these operations manually then by FORTRAN 5 * (11 – 5) ** 2 * 4 + 9 = 5 * (11 – 5) ** (2 * 4) + 9 = 5 * (11 – 5) ** 2 * (4 + 9) = 5 * (11 – 5) ** 2 * 4 / 9 = 5 * (11 – 5) ** 2 * 4.0 / 9 =

15 Q.2: Write a FORTRAN code to design an ID card for you to include the following: Name, ID No., Age, University and College. King Saud University Collage of Engineering Your Name Your ID No. Your Age


Download ppt "CHAPTER 2:BASIC FORTRAN Data Types INTEGER REAL COMPLEX CHARACTER LOGICAL."

Similar presentations


Ads by Google