ICS 101 Lab 3 Hossain Arif ICS Dept

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University.
1.1 Some Basics of Algebra Algebraic Expressions and Their Use
Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
1 Chapter 2: Data Types & Operations Part 3 ICS101: Computer Programming Al-Hashim, Amin G.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
Sets and Expressions Number Sets
Expressions & Assignments One of the original intentions of computer programs was the evaluation of mathematical expressions –languages would inherit much.
Objectives: To evaluate and simplify algebraic expressions.
Exponents & Scientific Notation MATH 102 Contemporary Math S. Rook.
Unit 3 Lesson 2: Rational Expressions
Exponent Rules and Dividing Polynomials Divide exponential forms with the same base. 2.Divide numbers in scientific notation. 3. Divide monomials.
CSI 3120, Expressions and assignment, page 1 Expressions and assignment Points for discussion Arithmetic expressions Overloading Logical expressions Assignment.
MM150 Unit 3 Seminar Agenda Seminar Topics Order of Operations Linear Equations in One Variable Formulas Applications of Linear Equations.
CHAPTER P SECTION 1 NOTES.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Evaluating Integer Expressions Friday, December 25, 2015.
Doing math In java.
Introduction to Exponents Definition: Let b represent a real number and n a positive integer. Then … b is called the base and n is called the exponent.
LAWS OF EXPONENTS.
 Constants A constant is a fixed value of a data type that cannot be changed Integer Constants Whole numbers → Do not have decimal points Examples: 83.
1 CS161 Introduction to Computer Science Topic #6.
CHAPTER 2:BASIC FORTRAN Data Types INTEGER REAL COMPLEX CHARACTER LOGICAL.
2-2 The Distributive Property Distributive Property of Multiplication over Addition : Ex. 3(2+6) Multiplication Addition You can distribute a factor to.
STRUCTURED PROGRAMMING C++ Operators. Content 2  C++ operators  Assignment operators  Arithmetic operators  Increment and decrement operators  Decision.
Exponents. 1. Relate and apply the concept of exponents (incl. zero). 2. Perform calculations following proper order of operations. 3. Applying laws of.
7-1 Integer Exponents 7-2 Powers of 10 and Scientific Notation 7-3 Multiplication Properties of Exponents 7-4 Division Properties of Exponents 7-5 Fractional.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
ISBN Chapter 7 Expressions and Assignments Statements.
Evaluating Algebraic Expressions 4-1Exponents AF2.1 Interpret positive whole-number powers as repeated multiplication and negative whole-number powers.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Exponential Notation 1-3.
Subtracting Integers #41.
Chapter 7: Expressions and Assignment Statements
Relational Operations
Chapter 7: Expressions and Assignment Statements
Multiplying and Dividing Integers
Learn to evaluate expressions with exponents.
RATIONAL EXPONENTS Basic terminology Substitution and evaluating
7.1 Integers Exponents.
For what number is 23 x 32 x 7 the prime factorization?
Arithmetic Operator Operation Example + addition x + y
Order of Operations Using Integers
Algebra Algebra.
Relational Operators Operator Meaning < Less than > Greater than
EXPONENTIAL EXPRESSIONS
Objective - To recognize and evaluate variable expressions.
EXPONENTIAL EXPRESSIONS
Chapter-3 Operators.
Order of Operations Using Integers
RATIONAL EXPONENTS Basic terminology Substitution and evaluating
Expressions.
Chapter 3 Operators and Expressions
Chapter 1 Section 1 Algebraic Expressions, Real Numbers, and Interval Notation.
Chapter Sections 1.1 – Study Skills for Success in Mathematics
Section 6.1 Order of Operations
Quotient Rules Integrated Math II 10.3.
The Selection Structure
Section 6.1 Order of Operations
Repetition (While Loop) LAB 9
OPERATORS in C Programming
Division Rules for Exponents
DATA TYPES AND OPERATIONS
EXPONENTIAL EXPRESSIONS
REPETITION Why Repetition?
OPERATORS in C Programming
Control Structures.
Presentation transcript:

ICS 101 Lab 3 Hossain Arif ICS Dept Logical Operations ICS 101 Lab 3 Hossain Arif ICS Dept

Objective What are Logical Operations What are Relational Operations What are Logical Expressions Logical Expressions Evaluation Examples Exercises

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

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

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

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

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.

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)

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

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

Examples .NOT. FLAG .AND. X * Y .GT. Z .OR. X + Y .GT. Z .NOT. FLAG .AND. 15.0 .GT. 10.0 .OR. 8.0 .GT. 10.0 .NOT. FLAG .AND. .TRUE. .OR. .FALSE. .TRUE. .AND. .TRUE. .OR. .FALSE. .TRUE. .OR. .FALSE. .TRUE.

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

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. 20.0 .OR. FLAG .AND. .NOT. Z .EQ. 5.0 .NOT. FLAG .AND. FLAG