Assignment statement and Arithmetic operation 2

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

Review Question What kind error is it when I try to multiply a number in a program by 1000 and store in a variable, but the variable is too small for the.
Congruence class arithmetic. Definitions: a ≡ b mod m iff a mod m = b mod m. a  [b] iff a ≡ b mod m.
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
Solving Linear Equations
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
Mathematics of Cryptography Part I: Modular Arithmetic
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
CSE1301 Computer Programming Lecture 5: C Primitives 2 Corrections.
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
Unit 3 Lesson 2: Rational Expressions
Created by S. Koch Solving One-Step Equations.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Selection Boolean What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean.
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
Arithmetic in Pascal A Short Glance We will learn the followings in this chapter Arithmetic operators Order of precedence Assignment statements Arithmetic.
CHAPTER 2 COMPONENTS OF A PROGRAMMING LANGUAGE I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Section 2.1 Solving Equations Using Properties of Equality.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Thinking Mathematically
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment.
© 2006 Pearson Education 1 Obj: to use assignment operators HW: Prelab Exercises 2 Quiz 3.1 – 3.4 in two class days  Do Now: 1.Read p.144 – 145 (3.4 “more.
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
One-Step Equations I can show that solving an equation leads to finding the value that makes the equation true.
Doing math In java.
Operators.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
SOLVING ONE-STEP EQUATIONS Integrated Math I Objective: Solve one-step linear equations in one variable with strategies involving inverse operations and.
Write, Interpret and Use Mathematical Expression and Equations.
Operators & Expressions
Subtracting Integers #41.
CSE 220 – C Programming Expressions.
Congruence class arithmetic
Addition/ Subtraction
ITEC113 Algorithms and Programming Techniques
Data Types, Identifiers, and Expressions
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Arithmetic operations & assignment statement
Assignment and Arithmetic expressions
Division with Remainders
COMPUTER 2430 Object Oriented Programming and Data Structures I
Arithmetic Operator Operation Example + addition x + y
OPERATORS (1) CSC 111.
Structure of a C Program
With Assignment Operator
Introduction to Variables, Algebraic Expressions, and Equations
EQ: How do I solve an equation in one variable?
ALGEBRA. ALGEBRA VARIABLES AND EXPRESSIONS Algebra – Uses symbols to represent quantities that are unknown or that vary. You can represent mathematical.
One step equation with Multiplication and Division
More Maths Programming Guides.
Two Step Equation.
THE COMPUTE STATEMENT Purpose: performs mathematical calculations
Doing Arithmetic Today’s lecture is in chapter 2 Assignment statement:
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Chapter 3 Operators and Expressions
Data Types and Expressions
Two step equation Brackets
OPERATORS in C Programming
5.03 Apply operators and Boolean expressions
Data Types and Expressions
Review Simplify 8 – 120 ÷ 5 • ÷ – 2 | 5 – 7 |
OPERATORS in C Programming
Data Types and Expressions
Presentation transcript:

Assignment statement and Arithmetic operation 2 +–×÷ Expressions and Operations

Expression Y A+B ; := NO, this is an EXPRESSION Let’s consider the following statement. Y A+B ; := Is it an EQUATION?

Expression OPERATOR ; A+B := Y OPERANDS

Expression Expression looks like a mathematical expression. The computer first evaluate the expression and the result will be stored in the variable on the left hand side

3+4+5 A+B*C/D (A+B)*(A+B)/(B-C) A*X*X+B*X+C Pi*RADIUS*RADIUS Here are some examples of expressions: 3+4+5 A+B*C/D (A+B)*(A+B)/(B-C) A*X*X+B*X+C Pi*RADIUS*RADIUS 4*A*A-Pi*A*A A+(N-1)*D

Addition + integer + integer => integer real + integer => real integer + real => real real + real => real

Subtraction – integer - integer => integer real - integer => real integer - real => real real - real => real

Multiplication * integer * integer => integer real * integer => real integer * real => real real * real => real

Real Division / integer / integer => real real / integer => real real / real => real

Integer operations (DIV and MOD) Quotient 5 3 16 15 1 Remainder 16 MOD 3

Integer Division integer DIV integer => integer real DIV integer => NOT ALLOWED integer DIV real => NOT ALLOWED real DIV real => NOT ALLOWED

Modulo integer MOD integer => integer real MOD integer => NOT ALLOWED integer MOD real => NOT ALLOWED real MOD real => NOT ALLOWED

Exercise 2 If A, B, C are integer variables, and D, E, F are real variables, which of the following statements are invalid? 1. C:=A+B-C VALID 2. C:=D+E-F; INVALID 3. A:=C/B - C/B; INVALID 4. E:=(A+B) / (A+B) VALID 5. D:= D DIV D INVALID 6. A:= A MOD A VALID 7. D:=A+A+B+B+C+C; VALID

A := 3 + 4 * 5; Precedence Please consider the following Add statement or Multiply first? A := 3 + 4 * 5;

Precedence ( ) - (unary minus) * , / , MOD, DIV +, - In PASCAL, the precedence is: ( ) - (unary minus) * , / , MOD, DIV +, -