Chapter 3 Arithmatic Operations 3.1 Operators An operator is a symbol or world that represents some operation that is performed on one or more data values.

Slides:



Advertisements
Similar presentations
Variables and Expressions
Advertisements

Chapter 1 Discovery 1 Evaluate each expression, and compare the results obtained in the left column with the corresponding results in the right column.
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
7.1Variable Notation.
Unit 12 INTRODUCTION TO ALGEBRA. 2 ALGEBRAIC EXPRESSIONS An algebraic expression is a word statement put into mathematical form by using variables, arithmetic.
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.
PRESENTATION 3 Signed Numbers
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
1. 5 word prediction. Guess the meanings of the following words: Variable, expression, base, constant, & factor.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
LESSON 6 – Arithmetic Operators
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
Chapter 1-1 Variables and Expressions In this section you will learn how to,  Write mathematical expressions given verbal expressions  And how to write.
PRESENTATION 11 What Is Algebra. ALGEBRAIC EXPRESSIONS An algebraic expression is a word statement put into mathematical form by using variables, arithmetic.
CHAPTER 2 COMPONENTS OF A PROGRAMMING LANGUAGE I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
C Operators. CONTENTS C OPERATORS TYPES OF OPERATOR UNARY BINARY TERNARY ARITHMATIC RELATIONAL LOGICAL.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
Variables and Algebraic Expressions 1-3. Vocabulary Variable- a letter represents a number that can vary. Constant- a number that does not change. Algebraic.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Chapter 8 Real Numbers and Introduction to Algebra.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Recap……Last Time [Variables, Data Types and Constants]
 Why is it important to understand the “language” of mathematics? CCCA Unit 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Chapter 1 Real Numbers and Introduction to Algebra.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
 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.
ICS102 Lecture 1 : Expressions and Assignment King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer.
Question of the Day Solve for b: 2b + 7 = 15. Expressions and Equations Collecting Like Terms and Distributive Property.
Chapter R Section 7: Radical Notation and Rational Exponents
Chapter 3 Math Operations. Objectives Use the assignment and arithmetic operators. Use operators in output statements. Explain the problem with division.
Variables, Operators, and Expressions
2 Chapter Chapter 2 Integers and Introduction to Variables.
Thinking Mathematically
INSPIRING CREATIVE AND INNOVATIVE MINDS
BIL 104E Introduction to Scientific and Engineering Computing
TMF1414 Introduction to Programming
Relational Operations
Arithmetic operations & assignment statement
Multiple variables can be created in one declaration
ALGEBRA VOCABULARY.
Chapter 7 Objectives Define basic terms in algebra: integer, number statement, expression, and coefficient Learn the relationships between positive and.
Arithmetic & other operations
Introduction to Algebra
Computer Programming: C language
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Lecture 3 Expressions Richard Gesick.
Writing expression basic
C Operators, Operands, Expressions & Statements
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.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Expressions and Assignment
Data Types and Expressions
Operators In Java Programming By Rajanikanth B.
Chapter 4: Expression and Operator
Algebraic expression to verbal statement two terms
OPERATORS in C Programming
is multiplied by a variable of type to yield a result of type
Data Types and Expressions
OPERATORS in C Programming
Data Types and Expressions
Presentation transcript:

Chapter 3 Arithmatic Operations 3.1 Operators An operator is a symbol or world that represents some operation that is performed on one or more data values. The data values are called operands and can be either variables or constants. For example, the addition operator, which is represented by the plus(+) sign, adds two numbers. The numbers to be added are the operands.

3.2 Assignment Statements The assignment statement is the primary means of assigning values to variables and for performing computations. The general form of the assignment statement is as follows: variable = arithmetic expression; For example: sum = sum + 3; The simplest form of assignment statement consists of the equal (=) symbol with a variable on the left and a constant on the right For example: x = 5;

3.3 Arithmetic Operators C provides operators for performing arithmetic operations such as addition, subtraction, multiplication, and division. Each operator is represented by a unique symbol. The arithmetic operations that can be performed and the corresponding symbols used for denoting the operation are shown as follows. Operator OperationSample Expression + addition x + y - subtraction x - y * multiplication x * y / division x / y % remainder x % y

3.4 Arithmetic Assignment Operators All the arithmetic operators can be combined with the assignment operator. The general format of an arithmetic assignment is as follows. variable operator = operand; Where operator is an arithmetic such as +,-,*,/, or %. Examples of statements containing arithmetic assignment operators and the equivalent assignment statements are given as follows.

Operator Meaning += add operand to variable and assign result to variable -= subtract operand from variable and assign result to variable *= multiply variable by operand and assign result to variable /= divide variable by operand and assign result to variable %= divide variable by operand and assign remainder to variable For Example: delta += 0.5;delta = delta + 0.5; new_val -= step_size;new_val = new_val - step_size; next_step *= 10;next_step = next_step * 10; zeta /= 100;zeta = zeta/100; a %= 2;a = a % 2;

3.5 Increment and Decrement Operators A common programming task consists of increasing or decreasing the value of a variable by 1. C has two operators, not usually found in other programming languages, to perform these tasks. They are the increment and decrement operators, ++ and --. The increment operator ++ adds one to its operand. For example, the statement x++; adds 1 to the value of x and is equivalent to x = x + 1; The decrement operator -- subtracts one from its operand. For example, the statement y--; y = y - 1;

We can put the increment and decrement operators either before the variable as in ++x; --y; or after the variable as in x++; y--; 3.6 Mathematical funtions Mathematical functions such as square roots, absolute values, logarithms, trigonometric and exponential functions appear routinely in a variety of engineering applications. Since these functions are commonly used, all C compilers provide a set of mathematical functions in their standard library.

NameDescription abs() absolute value of an int acos()arccosine asin()arcsine atan()arctangent cos()cosine cosh()hyperbolic cosine exp()exponential log()logarithm to the base 10 pow()x to the y power, x y sin()sine sinh()hyperbolic sine sqrt()square root tan()tangent tanh()hyperbolic tangent

The function declaration for the the mathematical functions are included in the file math.h. You should include this header file in all programs that use any of the mathematical functions. You can use the following preprocessor directive. Any Questions