160 likes | 385 Views
ICS101: Computer Programming. Chapter 2: Data Types & Operations. Part 1. Al-Hashim, Amin G. Outline. Data Types Constants Variables. Data Types. Data: form of recording 4 basic types of data in FORTRAN: Integer Real Character Logical. Constants. Fixed value Types:
E N D
ICS101: Computer Programming Chapter 2: Data Types & Operations Part 1 Al-Hashim, Amin G.
Outline • Data Types • Constants • Variables
Data Types • Data: form of recording • 4 basic types of data in FORTRAN: • Integer • Real • Character • Logical
Constants • Fixed value • Types: • Integer constants • Real constants • Character constants • Logical constants
Integer Constants • Numbers without a decimal point • E.g.: • 101 • 0 • -2008 • 1429
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) …
Character Constants • Any set of characters between single quotes • E.g.: • ‘FORTRAN is an interesting PL’ • ‘I’’am very interesting with ICS101’
Logical Constants • 2 logical constants in FORTRAN: • .TRUE. represents true • .FALSE. represents false
Variables • Occupies a place at the computer memory • Must have a name to be referenced • Its value can be changed
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
Cont. • Types of Variables : • Integer variables • Real variables • Character variables • Logical variables
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
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
Character Variables • Hold only character values • Definition: • ExplicitONLY… using the CHARACTER statement • CHARACTER NAME*6, COL*10, MAJOR • CHARACTER*6 NAME, COL*10, MAJOR • MUST be before any executable statement
Logical Variables • Hold only logical values (.TRUE. | .FALSE.) • Definition: • ExplicitONLY… using the LOGICAL statement • LOGICAL FLAG, TEST, X, CONT • MUST be before any executable statement
Exercise • Find the errors in the following FORTRAN code