Download presentation
Presentation is loading. Please wait.
1
1 Chapter 2: Data Types & Operations Part 1 ICS101: Computer Programming Al-Hashim, Amin G.
2
2 Outline Data Types Constants Variables
3
3 Data Types Data: form of recording 4 basic types of data in FORTRAN: Integer Real Character Logical
4
4 Constants Fixed value Types: Integer constants Real constants Character constants Logical constants
5
5 Integer Constants Numbers without a decimal point E.g.: 101 00 -2008 1429
6
6 Real Constants Numbers with a decimal point E.g.: 3.4 -0.0001 8710000000000.0 -0.0000000000000012 Representations in FORTRAN: Ordinarily Scientific Notation xEy (0.1≤ x <1.0) …
7
7 Character Constants Any set of characters between single quotes E.g.: ‘FORTRAN is an interesting PL’ ‘I’’am very interesting with ICS101’
8
8 Logical Constants 2 logical constants in FORTRAN: .TRUE. represents true .FALSE. represents false
9
9 Variables Occupies a place at the computer memory Must have a name to be referenced Its value can be changed
10
10 Cont. Rules of Naming Variables: Starts with an alphabetic character May contain digits Should not contain special characters Length should not exceed 6 characters Must not contain blanks Which of the following are legal variable names? (1) FIVE (2) 5IVE (3) F!VE (4) F I V E (5) FIVE55555 (6) F5
11
11 Cont. Types of Variables : Integer variables Real variables Character variables Logical variables
12
12 Integer Variables Hold only integer values Definition: Explicit … using the INTEGER statement INETGER X, Y, Z, FIVE Implicit … variable name starts with I, J, K, L, M, or N ISUM, JAR, KILO MUST be before any executable statement
13
13 Real Variables Hold only real values Definition: Explicit … using the REAL statement REAL TAX, FEE, Z, FIVE Implicit … variable name doesn’t start with I, J, K, L, M, or N SLOPE, WEIGHT, F6 MUST be before any executable statement
14
14 Character Variables Hold only character values Definition: Explicit ONLY… using the CHARACTER statement CHARACTER NAME*6, COL*10, MAJOR CHARACTER*6 NAME, COL*10, MAJOR MUST be before any executable statement
15
15 Logical Variables Hold only logical values (.TRUE. |.FALSE.) Definition: Explicit ONLY… using the LOGICAL statement LOGICAL FLAG, TEST, X, CONT MUST be before any executable statement
16
16 Exercise Find the errors in the following FORTRAN code * FullOfErrors.for C By: Al-Hashim INTEGER OFFICE#, HOURS, MINUTES SECONDS CHARACTER E-MAIL*100LOGIC FLAG PRINT*, ICS101: COMPUTER PROGRAMMING REAL CASH1, CASH2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.