Download presentation
Presentation is loading. Please wait.
1
ICS 101 Lab 3 Hossain Arif ICS Dept
Logical Operations ICS 101 Lab 3 Hossain Arif ICS Dept
2
Objective What are Logical Operations What are Relational Operations
What are Logical Expressions Logical Expressions Evaluation Examples Exercises
3
Arithmetic Operations(1)
Arithmetic operators Precedence Math Notation Example Operation FORTRAN Operator 1 XY X ** Y Exponentiation ** 2 X x Y X * Y Multiplication * X ÷ Y X / Y Division / 3 X + Y Addition + X - Y Subtraction - Parentheses () have the highest precedence
4
Arithmetic Operations(2)
Two restrictions No two operators must appear consecutively 2 * -3 should be written as 2 * (-3) Exponential operator must not be used to raise a negative number to a real exponent (-2.0) ** 1.5 and (-3) ** 2.3 are not allowed in FORTRAN
5
Arithmetic Operations(3)
Integer operations An operator between two integer operands Produces integer results In division, the fraction part is truncated Examples: 50 – 23 3 ** 2 5 * 7 8 / 3 9 / 10 17 / 6 * 6
6
Arithmetic Operations(4)
Real operations An operator between two real operands Produces real results Examples: 50.0 – 23.0 3.0 ** 2.0 5.0 * 7.0 9. / 10. 9.3 / 3.2
7
Arithmetic Operations(5)
Mixed-mode operations An operator between an integer operand and a real operand Produces real results Examples: 50 – 23.0 3.0 ** 2 , 3 ** 2.0 65.7 / 7 8.0 / 2 9 / 10.
8
Logical Operations(1) Logical Operations Logical Operators: .NOT. P
Evaluate to either .TRUE. or .FALSE. Logical Operators: .NOT. P P .OR. Q P .AND. Q Q P .TRUE. .FALSE. .NOT. operator has the highest precedence (1) followed by .AND. (2) then .OR. (3)
9
Logical Operations(2) Relational operators Example Math Operator
X .EQ. Y = .EQ. N .NE. 8 ≠ .NE. P .GT. 7.3 > .GT. SM .GE. TOT ≤ .GE. A+B .LT. A*2.0 < .LT. NUM .LE. C ≥ .LE. Relational operators have lower precedence than arithmetic operators and higher precedence than logical operators
10
Logical Operations(3) Logical expressions
Evaluated to .TRUE. or .FALSE. May contain different types of variables and operators Examples: .NOT. FLAG .AND. X * Y .GT. Z .OR. X + Y .GT. Z Where X has a value of 3.0, Y has a value of 5.0, Z has a value of 10.0, and FLAG is logical variable with .FALSE. value K / L * L .EQ. K Where K and L are integers
11
Examples .NOT. FLAG .AND. X * Y .GT. Z .OR. X + Y .GT. Z
.NOT. FLAG .AND GT OR GT. 10.0 .NOT. FLAG .AND. .TRUE. .OR. .FALSE. .TRUE. .AND. .TRUE. .OR. .FALSE. .TRUE. .OR. .FALSE. .TRUE.
12
Precedence Summary Arithmetic Operators (1) Relational Operators (2)
Exponentiation (I) Multiplication / Division (II) Addition / Subtraction (III) Relational Operators (2) Logical Operators (3) .NOT. (#) .AND. (##) .OR. (###) To change Precedence (Priority) use Parentheses
13
Exercise Find the value for each of the following expressions
X= 3.0, Y = 5.0, Z = 10.0, FLAG = .FALSE. .NOT. FLAG .OR. FLAG X .GT. Y – Z / 2.0 X * Z .EQ OR. FLAG .AND. .NOT. Z .EQ. 5.0 .NOT. FLAG .AND. FLAG
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.