[PDF] c++ maths operation
[PDF] c++ stl pdf
[PDF] c-maths application form
[PDF] c.a.g francais
[PDF] c.g.n.c code général de normalisation comptable maroc
[PDF] c2i qcm pdf
[PDF] c3 temps partiel télécharger
[PDF] c=m/v
[PDF] ca de franche comté en ligne
[PDF] ca fop 2015 cote d'ivoire
[PDF] ca fop 2016 la date du deuxieme tour
[PDF] ca form 568 question m
[PDF] ca ille et vilaine
[PDF] ca nhac quan ho bac ninh
[PDF] ca nuong giay bac xuan hong
PROG0101 Fundamentals of Programming
1
PROG0101
FUNDAMENTALS OF PROGRAMMING
Chapter 5
Operators
PROG0101 Fundamentals of Programming
2
Operators
Topics
Operators
Arithmetic Operators
Relational Operators
Logical Operators
Increment and Decrement Operators
PROG0101 Fundamentals of Programming
3
Operators
Operators
Anoperatorisasymbol,whichhelpstheuserto
orlogicalmanipulations.
Operatorsareusedinprogramminglanguage
programtooperateondataandvariables.
PROG0101 Fundamentals of Programming
4
Operators
Operators
Operatorscanbeclassifiedas:
Arithmeticoperators
RelationalOperators
LogicalOperators
IncrementsandDecrementOperators
PROG0101 Fundamentals of Programming
5
Operators
Arithmetic Operators
numericvalues.
OperatorNameDescription
+Additionto add two numbers together -Subtractionto subtract one number from another *Multiplicationto multiply one number by another. /Divisionto divide one number by another. %Modulus (Remainder) to find the remainder from dividing one number by another.
PROG0101 Fundamentals of Programming
6
Operators
Arithmetic Operators
Example:
i.5+3=8 ii.53=2 iii.5*3=15 iv.5/3=1 v.5%3=2
PROG0101 Fundamentals of Programming
7
Operators
Arithmetic Operators
*,/and%willbeperformedbefore+or-inany expression. evaluationtothis.
PROG0101 Fundamentals of Programming
8
Operators
Arithmetic Operators
Example
i.2 + 5 * 4 3 = ? ii.(2 + 5) * (4 3) = ?
PROG0101 Fundamentals of Programming
9
Operators
Arithmetic Operators
assignmentstatements: i.z = x + y ii.no1 = x y iii.age = a * b + c iv.velocity = distance / time v.force = mass * acceleration vi.count = count + 1
PROG0101 Fundamentals of Programming
10
Operators
Integer Arithmetic
calledasintegerarithmetic.
Italwaysgivesanintegerastheresult.
PROG0101 Fundamentals of Programming
11
Operators
Integer Arithmetic
Example
Letx=27andy=5betwointegernumbers.Thenthe
i.x + y = 32 ii.x y = 22 iii.x * y = 115 iv.x % y = 2 v.x / y = 5
PROG0101 Fundamentals of Programming
12
Operators
Floating-point Arithmetic
iscalledfloating-pointarithmetic.
PROG0101 Fundamentals of Programming
13
Operators
Floating-point Arithmetic
Example
Let x = 14.0 and y = 4.0 then
i.x + y = 18.0 ii.x y = 10.0 iii.x * y = 56.0 iv.x / y = 3.50
PROG0101 Fundamentals of Programming
14
Operators
Relational Operators
Anoperatorthatcomparestwovalues.
Forexample,theexpression:
ThisexpressionwillhaveavalueofTRUEifthe
expressionwillbeFALSE. x < 5 means x is less than 5
PROG0101 Fundamentals of Programming
15
Operators
Relational Operators
Relationaloperatorsaresometimescalled
comparisonoperators. calledrelationalexpressions.
Whereexp1andexp2areexpressions,whichmay
them.
relational operator PROG0101 Fundamentals of Programming
16 Operators
Relational Operators
Thefollowingarerelationaloperators:
OperatorNameDescription
Indicates whether the value of the left operand is less than the value of the right operand. <=Less than or equal to Indicates whether the value of the left
operand is less than or equal to the value of the right operand. >Greater than Indicates whether the value of the left
operand is greater than the value of the right operand. >=Greater than or equal to Indicates whether the value of the left
operand is greater than or equal to the value of the right operand. PROG0101 Fundamentals of Programming
17 Operators
Relational Operators
Thefollowingarerelationaloperators:
OperatorNameDescription
==Equal to Indicates whether the value of the left
operand is equal to the value of the right operand. !=Not equal to Indicates whether the value of the left
operand is not equal to the value of the right operand. PROG0101 Fundamentals of Programming
18 Operators
Relational Operators
Example:
Letx=2andy=5then
i.x < y = True ii.(x + 2) > (y * 2)= False iii.(x + 3) <= y = True iv.x != y = True v.y > (3 + x)= False PROG0101 Fundamentals of Programming
19 Operators
Logical Operators
relationalexpressions. Thefollowingarelogicaloperators:
OperatorName
&&LogicalAND ||LogicalOR !Logical NOT PROG0101 Fundamentals of Programming
20 Operators
Logical AND
expressionistrue. Exp1Exp2Exp1 && Exp2
FalseFalseFalse
TrueFalseFalse
FalseTrueFalse
TrueTrueTrue
PROG0101 Fundamentals of Programming
21
Operators
Logical AND
Example:
(a > b) && (x == 10) equalto10. PROG0101 Fundamentals of Programming
22
Operators
Logical AND
Example:
Givena=2,b=3andc=5,evaluatethefollowing
logicalexpressions: i.(a > b) && (c != 5)= False ii.(a < b) && (c < b)= False iii.(a > b) && (c == 5) = False iv.(a < b) && (b < c)= True PROG0101 Fundamentals of Programming
23
Operators
Logical OR
istrue. orifbothofthemaretrue. Exp1Exp2Exp1 || Exp2
FalseFalseFalse
TrueFalseTrue
FalseTrueTrue
TrueTrueTrue
PROG0101 Fundamentals of Programming
24
Operators
Logical OR
Example:
(a < m) || (a < n) trueorifbothofthemaretrue. PROG0101 Fundamentals of Programming
25
Operators
Logical OR
Example:
Givena=2,b=3andc=5,evaluatethefollowing
logicalexpressions: i.(a > b) || (c != 5)= False ii.(a < b) || (c < b)= True iii.(a > b) || (c == 5) = True iv.(a < b) || (b < c)= True PROG0101 Fundamentals of Programming
26
Operators
Logical NOT
evaluatestofalseiftheexpressionistrue. Inotherwordsitjustreversesthevalueofthe
expression. Exp1!Exp1
TrueFalse
FalseTrue
PROG0101 Fundamentals of Programming
27
Operators
Logical NOT
Example:
! (x >= y) ofxisneithergreaterthanorequaltoy PROG0101 Fundamentals of Programming
28
Operators
Logical NOT
Example:
Givena=2,b=3andc=5,evaluatethefollowing
logicalexpressions: a) !(a > b)= True b) !(a < b) = False c) !(a > b || c == 5)= False PROG0101 Fundamentals of Programming
29
Operators
Increment and Decrement Operators
theunaryoperatorswhichareveryusefulin programminglanguage. Theyareextensivelyusedinloops.
Thesyntaxoftheoperatorsisgivenbelow:
++ variable name variable name++ quotesdbs_dbs21.pdfusesText_27