CC112 Structured Programming Lecture 4 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.

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

Arithmetic Calculations
7.1Variable Notation.
Computer Science 1620 Arithmetic. C++ Math we have seen how to use numbers in our program to represent data however, we can also manipulate this data.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
ICS 103 Lab 2-Arithmetic Expressions. Lab Objectives Learn different arithmetic operators Learn different arithmetic operators Learn how to use arithmetic.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
CSI 101 Elements of Computing Spring 2009 Lecture #1 – From Math to Computers Wednesday, January 21, 2009.
Chapter 3 Math Vocabulary
3-3 Solving Multiplication Equations. Solve Solution GOAL Find the value of the variable that makes the equation TRUE. The value that makes the equation.
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
Operaciones y Variables
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
A Review of Programming and C++
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Numeric Types, Expressions, and Output ROBERT REAVES.
The Rational Zero Theorem The Rational Zero Theorem gives a list of possible rational zeros of a polynomial function. Equivalently, the theorem gives all.
MTH 104 Calculus and Analytical Geometry Lecture No. 2.
Ch 1.3 – Order of Operations
7.6 Rational Zero Theorem Algebra II w/ trig. RATIONAL ZERO THEOREM: If a polynomial has integer coefficients, then the possible rational zeros must be.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
CPS120: Introduction to Computer Science Operations Lecture 9.
CHAPTER 2 COMPONENTS OF A PROGRAMMING LANGUAGE I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
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
In this lesson you will learn another way to define a sequence — by a recursive rule. So far you have worked with explicit rules for the n th term of a.
CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
 Term- number or product of a number and a variable  Constant- term with no variable  Coefficient- number that multiplies to a variable  Like Terms-
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Doing math In java.
Warm Up Simplify.  3   15  (9 + 2)  7  5
Solving 1-Step Equations 2 An Equation is Like a Balance.
Equations Inequalities = > 3 5(8) - 4 Numerical
STROUD Worked examples and exercises are in the text PROGRAMME F3 EXPRESSIONS and EQUATIONS.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
1 Lecture Three I/O Formatting and Arithmetic Dr. Sherif Mohamed Tawfik.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
STROUD Worked examples and exercises are in the text 1 STROUD Worked examples and exercises are in the text Programme F3: Expressions and equations PROGRAMME.
Variables, Operators, and Expressions
CSE 220 – C Programming Expressions.
ARITHMETIC IN C Operators.
INSPIRING CREATIVE AND INNOVATIVE MINDS
Test Review Computer Science History
Arithmetic operations & assignment statement
Introduction to Algebra
Assignment statement and Arithmetic operation 2
Warm-up September 14, 2017 Change to a decimal: 87% 7%
Operators and Expressions
Structure of a C Program
Using Recursive Rules for Sequences
Lecture 3 Expressions Richard Gesick.
Ch. 9 Vocabulary 8.) quadratic equation
C Operators, Operands, Expressions & Statements
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
A mathematical phase containing numbers.
A mathematical phase containing numbers.
Chapter 2, Part III Arithmetic Operators and Decision Making
4.3: Solving (Quadratic Equations) by Factoring
Presentation transcript:

CC112 Structured Programming Lecture 4 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer Engineering Department

L ECTURE 4 Arithmetic operations 2

i. Arithmetic Operators Shortcut assignment Prefix form Postfix form ii. Arithmetic Expression Precedence rules Evaluate the expression iii. Math in C Math library Math library examples 3 L ECTURE O UTLINE

I.A RITHMETIC OPERATORS Most C programs perform calculations using the C arithmetic operators Note the use of various special symbols not used in algebra. In algebra, to multiply a times b, we simply place these single-letter variable names side by side as in ab. In C, however, if we were to do this, ab would be interpreted as a single, two-letter name (or identifier). Therefore, C requires that multiplication be explicitly denoted by using the * operator as in a*b. 4

5 I.A RITHMETIC OPERATORS

6

Division and the Remainder Operator C provides the remainder (modulus) operator, %, which yields the remainder after integer division. The remainder operator is an integer operator that can be used only with integer operands. The expression x % y yields the remainder after x is divided by y. Thus, 7 % 4 yields 3 and 17 % 5 yields 2. I.A RITHMETIC OPERATORS 7

Shortcut assignment 8 I.A RITHMETIC OPERATORS

Prefix form I.A RITHMETIC OPERATORS 9

Postfix form I.A RITHMETIC OPERATORS 10

II.A RITHMETIC EXPRESSION 11 An expression is a valid arrangement of variables, constants, and operators. In C each expression can be evaluated to compute a value of a given type

Rules of Operator Precedence C applies the operators in arithmetic expressions in a precise sequence determined by the following rules of operator precedence, which are generally the same as those in algebra: II.A RITHMETIC EXPRESSION 12

Rules of Operator Precedence EXAMPLE: II.A RITHMETIC EXPRESSION 13

Math library The C math library provides a lot of useful predefined math functions. A function is a subprogram used to do a certain task. A function has zero or more inputs ( called parameters), and zero or one output (called return value) II.M ATH IN C 14 function Inputs Output

Math library Before you use them, remember to include the math library in your code: #include function sqrt: y = sqrt ( x ); II.M ATH IN C 15

16 II.M ATH IN C Math library

17 II.M ATH IN C Example 1: Write a program to get the roots of a quadratic equation, given the 3 coefficients a, b, and c, a x 2 + b x + c = 0 Solution: Root 1 = Root 2 =

18