SlideShare ist ein Scribd-Unternehmen logo
1 von 44
DTI2143 Computer Programming 1 Chapter 3 Expression & Operators
Aim 2 To give understanding on: ,[object Object]
math.h and stdlib.h built-in functionObjective Students should be able to: ,[object Object],  operator. ,[object Object],[object Object]
4 Introduction to Expression Process involves in money withdrawal scenario balance – withdrawed money = current balance Expression in C : bakiTerkini =wangKeluar – bakiSemasa;
What is Expression? 5 Introduction to Expression Combination or more than one variable or  Constant (operand) which separated by  operator Expression Operator example x + 3  -   z Operand Consists of arithmetic relational logical
6 Arithmetic Expression Known as Arithmetic Expression Mathematic Expression using Arithmetic Operator Represents by Represents by Unary operator Binary operator
Unary Operator 7 Arithmetic Expression Unary Operator Operates for one operand Computer memory cell example -20 a  = -20; a b  = +15; b +15
Unary Operator 8 Arithmetic Expression Example 1: int  A = 5; ++A;  printf(“%d”, A);                     output ? A--; printf(“%d”,A);                      output ? A++; printf(“%d”,A);                      output ?
Unary Operator 9 Arithmetic Expression Example 2: int  A ; A=6; printf(“%d”,3 + --A);       output ? printf(“%d”, A);               output ? A=6; printf(“%d”, 3 + A--);       output ? printf(“%d”, A);                output ?
Unary Operator 10 Arithmetic Expression Example 3: Given the value of  num1 = 8 .Determine the value of num2 after the execution for each of the following statements:  num2 = num1++ - 2; num2 = num1; num2 = ++num1 – 3; num2 = num1-- +1;
11
Binary Operator 12 Arithmetic Expression Located between constants or  variables or both combination Binary Operator example A+    z operator operand
Binary Operator 13 Arithmetic Expression Multiplication Use symbol  “ * ” example A  *    z operator operand Mathematic Arithmetic Expression 2x + y 2 * x + y
Binary Operator 14 Arithmetic Expression Divide Use symbol  “/” example A   /    z operator operand Mathematic Arithmetic Expression 2 :  y 2 / y
Binary Operator 15 Arithmetic Expression Modulus Use symbol  “%” example A   %    z operator operand Return a balance when 2 numbers is divided Can only be used with an integer variable
Binary Operator 16 Arithmetic Expression Example: int  A, B;  float C;  A= 2;  B= 5;  C= 2.4;  B% A;  C % A; Valid!   Answer is 1 Invalid! C is float
Assignment Statement 17 Arithmetic Expression ,[object Object]
Use operator symbol  =Assignment statement Double assignment statement Compound assignment statement
Assignment Statement 18 Arithmetic Expression ,[object Object],variable = value; 	variable = constant; or variable = variable; 	variable = expression; ,[object Object],1.average= ( 6 + 5) * 4; 2.grossSalary = 1500; nettSalary = grossSalary + 200; 3.price= 50.00;    pay = price; ` 44 average 1500 grossSalary 1700 nettSalary 50.00 price pay 50.00
19 Arithmetic Expression Compound Assignment Statement ,[object Object]
Example :int a = b= c = d = e = 250; int b =2, number =0, total = 0,average =3;  number = b++ = 10; int age = workHour = 0;
20 Arithmetic Expression Compound Assignment Statement Function ,[object Object]
To simplify arithmetic operator
Original function of operator does not affected
Allowed combination are as follow:operator: += , -= , *= , /= , %=
Compound Assignment Statement 21 Arithmetic Expression Example :
Arithmetic Operator Precedence Rules 22 Arithmetic Expression Compiler will follows the following precedence to execute the arithmetic expression based on priority.
Arithmetic Operator Precedence Rules 23 Arithmetic Operator Example: 5 + 2 * 6 – 4 / 2 5  +  12  - 4 / 2        5  + 12  -    2            17 - 2               15 2.	3 * 4 / 2 + ( 3 –1)        3 * 4 / 2 +    2          12   / 2 + 2 		 6  +  2 		     8
Arithmetic Operator Precedence Rules 24 Arithmetic Expression Example: 3. Prefix unary arithmetic expression intkira = 5, nilaipertama = 10; nilai_kedua = 5 * --kira + nilai_pertama; printf(“%d %d”, kira, nilai_kedua); Output: 4  30
Arithmetic Operator Precedence Rules 25 Arithmetic Expression Example: 3. Prefix unary arithmetic expression     int kira = 5, nilai pertama = 10;     nilai_kedua = 5 * kira-- + nilai_pertama;     printf(“%d %d”, kira, nilai_kedua); Output: 4  35
26 Arithmetic Expression Mathematic Library Function ,[object Object]
Dipanggilbersama#include
Antarafungsiperpustakaanmatematik yang penting:,[object Object]
Exercise: 28 Arithmetic Expression Convert the following mathematic expression to a valid arithmetic expression : 	a)  b = 3 + bb) x  = (a – b)(a – c2)                     a + 4        c) d = (3e – d) -  ( 4 – 3c3 )     d) r = 2s + 3(s – 9) 		       x – 9           4y		                s Given a= 3, b = 5, c=1.  What is the output of the following expression? 	a.  ( 6 * c – 6 / a) -  b                   b.   (5 * c) +( a* b / b)        c.   ++a 			        d.    c  + a * c / (3 * c)
Exercise: 29 Arithmetic Expression       Assume i,j and k are integer variables with i = 5 and j=3. Determine what is the value for each of the following statement: 	a)	k = j++;		d)   k = ++j;		 	b)	k = i * j--;		e)   k = i * --j; 	c)	k = j + i * j++;		f)    k = 27 / j++ - 16 % i;
30 Relation Expression Relational expression use Relational operator Combination of more than one statement variable vs variable Can consists of variable vs constant produce constant vs constant 0 (if false) 1(if true)
Relational Operator 31 Relation Expression
32 Relation Expression P/s: a, b and  c are variables, Replace with the given values Example 1: int a=6, b =1, c = -2; a+ b == c			2) a !=  b 	6 + 1== -2			    6 != 1 	7 == -2 Answer: 0(False)		    Answer : 1 (True)
33 Relation Expression Example 2 : int a=6, b =1, c = -2;   3)	b < a			4) b + c <= a 	1 < -2			    1 + -2 < 6 					    -1 < 6 Answer: 0 (False)           Answer : 1 (True)
34 Relation Expression P/s: Relational operator has less priority than other operators. Start evaluating from left to right. Example 3: int a=10, b = 3, c = 7; (a+b >= 3*c)==( a != 2*c+b) (10+3 >= 3*7)==(a != 2*c+b) (13 >= 21)==(10 != 14+3) (13 >= 21)==(10 != 17) 0 == 1 0 (false)
35 Relation Expression An example program which uses relational expression #include <stdio.h> void main() {  int age; printf(“Please enter your age >>”); scanf(“%d”,&age);     if   (age > 21) printf(“You are qualified to vote”); } Relational expression
36 Logical Expression Logical Operator Logical expression use Combination of one or more expressions Can consists of Relational expr. vs logical expr. Relational expr. vs variable produces Relational expr. vs constant 0 (if false) 1(if true)
37 Logical Expression Logical Operator Logical operator && dan || is used between 2 or more relational expression
38 Logical Expression Logical operator truth table for AND AND (&&)

Weitere Àhnliche Inhalte

Was ist angesagt?

C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
guest58c84c
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
eShikshak
 

Was ist angesagt? (18)

C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
ICP - Lecture 5
ICP - Lecture 5ICP - Lecture 5
ICP - Lecture 5
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
Chapter 2 : Balagurusamy_ Programming ANsI in C
Chapter 2 :  Balagurusamy_ Programming ANsI in CChapter 2 :  Balagurusamy_ Programming ANsI in C
Chapter 2 : Balagurusamy_ Programming ANsI in C
 
Python Basic Operators
Python Basic OperatorsPython Basic Operators
Python Basic Operators
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in c
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Unit 2
Unit 2Unit 2
Unit 2
 
Expressions in c++
 Expressions in c++ Expressions in c++
Expressions in c++
 
Project in TLE
Project in TLEProject in TLE
Project in TLE
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in C
 
Report Group 4 Constants and Variables
Report Group 4 Constants and VariablesReport Group 4 Constants and Variables
Report Group 4 Constants and Variables
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 

Andere mochten auch

Problemas resoltos new
Problemas resoltos newProblemas resoltos new
Problemas resoltos new
juanapardo
 
Apuntes
Apuntes Apuntes
Apuntes
juanapardo
 
Components of a computer
Components of a computerComponents of a computer
Components of a computer
TechTeacher803
 
Tema 2 cmc
Tema 2 cmcTema 2 cmc
Tema 2 cmc
juanapardo
 
ĐœĐŸĐŽĐ”Đ»ŃŒ Đ°ĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·ĐžŃ€ĐŸĐČĐ°ĐœĐœĐŸĐč ŃĐžŃŃ‚Đ”ĐŒŃ‹ ĐŒĐŸĐœĐžŃ‚ĐŸŃ€ĐžĐœĐłĐ° Ń€Đ”Đ·ŃƒĐ»ŃŒŃ‚Đ°Ń‚ĐžĐČĐœĐŸŃŃ‚Đž ĐżŃ€ĐŸŃ†Đ”ŃŃĐ° ĐŸĐ±ŃƒŃ‡Đ”...
ĐœĐŸĐŽĐ”Đ»ŃŒ Đ°ĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·ĐžŃ€ĐŸĐČĐ°ĐœĐœĐŸĐč ŃĐžŃŃ‚Đ”ĐŒŃ‹ ĐŒĐŸĐœĐžŃ‚ĐŸŃ€ĐžĐœĐłĐ° Ń€Đ”Đ·ŃƒĐ»ŃŒŃ‚Đ°Ń‚ĐžĐČĐœĐŸŃŃ‚Đž ĐżŃ€ĐŸŃ†Đ”ŃŃĐ° ĐŸĐ±ŃƒŃ‡Đ”...ĐœĐŸĐŽĐ”Đ»ŃŒ Đ°ĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·ĐžŃ€ĐŸĐČĐ°ĐœĐœĐŸĐč ŃĐžŃŃ‚Đ”ĐŒŃ‹ ĐŒĐŸĐœĐžŃ‚ĐŸŃ€ĐžĐœĐłĐ° Ń€Đ”Đ·ŃƒĐ»ŃŒŃ‚Đ°Ń‚ĐžĐČĐœĐŸŃŃ‚Đž ĐżŃ€ĐŸŃ†Đ”ŃŃĐ° ĐŸĐ±ŃƒŃ‡Đ”...
ĐœĐŸĐŽĐ”Đ»ŃŒ Đ°ĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·ĐžŃ€ĐŸĐČĐ°ĐœĐœĐŸĐč ŃĐžŃŃ‚Đ”ĐŒŃ‹ ĐŒĐŸĐœĐžŃ‚ĐŸŃ€ĐžĐœĐłĐ° Ń€Đ”Đ·ŃƒĐ»ŃŒŃ‚Đ°Ń‚ĐžĐČĐœĐŸŃŃ‚Đž ĐżŃ€ĐŸŃ†Đ”ŃŃĐ° ĐŸĐ±ŃƒŃ‡Đ”...
Mikhail Bogdanov
 
Ance_Mundula_24052011
Ance_Mundula_24052011Ance_Mundula_24052011
Ance_Mundula_24052011
RĂšdais
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
alish sha
 
Cuestions xenetica molecular_e_acidos_nucleicos
Cuestions xenetica molecular_e_acidos_nucleicosCuestions xenetica molecular_e_acidos_nucleicos
Cuestions xenetica molecular_e_acidos_nucleicos
juanapardo
 
Preparazione precampionato anno 1977 1978
Preparazione precampionato anno 1977 1978Preparazione precampionato anno 1977 1978
Preparazione precampionato anno 1977 1978
Stefano Merlo
 

Andere mochten auch (20)

Problemas resoltos new
Problemas resoltos newProblemas resoltos new
Problemas resoltos new
 
Proceso de cambios vip
Proceso de cambios vipProceso de cambios vip
Proceso de cambios vip
 
Apuntes
Apuntes Apuntes
Apuntes
 
Components of a computer
Components of a computerComponents of a computer
Components of a computer
 
ă‚Șă‚Šăƒłăƒ‰ăƒĄăƒ‡ă‚Łă‚ąæ™‚ä»Łă ă‹ă‚‰ă“ăïŒ MTă‚Żăƒ©ă‚Šăƒ‰ç‰ˆăžăźæœŸćŸ…ăšäžæș€
ă‚Șă‚Šăƒłăƒ‰ăƒĄăƒ‡ă‚Łă‚ąæ™‚ä»Łă ă‹ă‚‰ă“ăïŒ MTă‚Żăƒ©ă‚Šăƒ‰ç‰ˆăžăźæœŸćŸ…ăšäžæș€ă‚Șă‚Šăƒłăƒ‰ăƒĄăƒ‡ă‚Łă‚ąæ™‚ä»Łă ă‹ă‚‰ă“ăïŒ MTă‚Żăƒ©ă‚Šăƒ‰ç‰ˆăžăźæœŸćŸ…ăšäžæș€
ă‚Șă‚Šăƒłăƒ‰ăƒĄăƒ‡ă‚Łă‚ąæ™‚ä»Łă ă‹ă‚‰ă“ăïŒ MTă‚Żăƒ©ă‚Šăƒ‰ç‰ˆăžăźæœŸćŸ…ăšäžæș€
 
æ„›çŸ„äž­ć°äŒæ„­ćź¶ćŒć‹äŒšIt研究䌚
æ„›çŸ„äž­ć°äŒæ„­ćź¶ćŒć‹äŒšItç ”ç©¶äŒšæ„›çŸ„äž­ć°äŒæ„­ćź¶ćŒć‹äŒšIt研究䌚
æ„›çŸ„äž­ć°äŒæ„­ćź¶ćŒć‹äŒšIt研究䌚
 
Tema 2 cmc
Tema 2 cmcTema 2 cmc
Tema 2 cmc
 
ĐœĐŸĐŽĐ”Đ»ŃŒ Đ°ĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·ĐžŃ€ĐŸĐČĐ°ĐœĐœĐŸĐč ŃĐžŃŃ‚Đ”ĐŒŃ‹ ĐŒĐŸĐœĐžŃ‚ĐŸŃ€ĐžĐœĐłĐ° Ń€Đ”Đ·ŃƒĐ»ŃŒŃ‚Đ°Ń‚ĐžĐČĐœĐŸŃŃ‚Đž ĐżŃ€ĐŸŃ†Đ”ŃŃĐ° ĐŸĐ±ŃƒŃ‡Đ”...
ĐœĐŸĐŽĐ”Đ»ŃŒ Đ°ĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·ĐžŃ€ĐŸĐČĐ°ĐœĐœĐŸĐč ŃĐžŃŃ‚Đ”ĐŒŃ‹ ĐŒĐŸĐœĐžŃ‚ĐŸŃ€ĐžĐœĐłĐ° Ń€Đ”Đ·ŃƒĐ»ŃŒŃ‚Đ°Ń‚ĐžĐČĐœĐŸŃŃ‚Đž ĐżŃ€ĐŸŃ†Đ”ŃŃĐ° ĐŸĐ±ŃƒŃ‡Đ”...ĐœĐŸĐŽĐ”Đ»ŃŒ Đ°ĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·ĐžŃ€ĐŸĐČĐ°ĐœĐœĐŸĐč ŃĐžŃŃ‚Đ”ĐŒŃ‹ ĐŒĐŸĐœĐžŃ‚ĐŸŃ€ĐžĐœĐłĐ° Ń€Đ”Đ·ŃƒĐ»ŃŒŃ‚Đ°Ń‚ĐžĐČĐœĐŸŃŃ‚Đž ĐżŃ€ĐŸŃ†Đ”ŃŃĐ° ĐŸĐ±ŃƒŃ‡Đ”...
ĐœĐŸĐŽĐ”Đ»ŃŒ Đ°ĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·ĐžŃ€ĐŸĐČĐ°ĐœĐœĐŸĐč ŃĐžŃŃ‚Đ”ĐŒŃ‹ ĐŒĐŸĐœĐžŃ‚ĐŸŃ€ĐžĐœĐłĐ° Ń€Đ”Đ·ŃƒĐ»ŃŒŃ‚Đ°Ń‚ĐžĐČĐœĐŸŃŃ‚Đž ĐżŃ€ĐŸŃ†Đ”ŃŃĐ° ĐŸĐ±ŃƒŃ‡Đ”...
 
Teaching people how to treat you
Teaching people how to treat youTeaching people how to treat you
Teaching people how to treat you
 
PBL Lesson Plan C
PBL Lesson Plan CPBL Lesson Plan C
PBL Lesson Plan C
 
Workplace violence by Brad Hyde
Workplace violence by Brad HydeWorkplace violence by Brad Hyde
Workplace violence by Brad Hyde
 
Cloud Communicatie Detron 2012
Cloud Communicatie Detron 2012Cloud Communicatie Detron 2012
Cloud Communicatie Detron 2012
 
Ance_Mundula_24052011
Ance_Mundula_24052011Ance_Mundula_24052011
Ance_Mundula_24052011
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
Nha Tran Brand Brief
Nha Tran Brand BriefNha Tran Brand Brief
Nha Tran Brand Brief
 
Cuestions xenetica molecular_e_acidos_nucleicos
Cuestions xenetica molecular_e_acidos_nucleicosCuestions xenetica molecular_e_acidos_nucleicos
Cuestions xenetica molecular_e_acidos_nucleicos
 
Preparazione precampionato anno 1977 1978
Preparazione precampionato anno 1977 1978Preparazione precampionato anno 1977 1978
Preparazione precampionato anno 1977 1978
 
Los secretos de las presentaciones de Steve Jobs
Los secretos de las presentaciones de Steve JobsLos secretos de las presentaciones de Steve Jobs
Los secretos de las presentaciones de Steve Jobs
 
THE POWER PRINCIPLES OF TEAM BUILDING
THE POWER PRINCIPLES OF TEAM BUILDINGTHE POWER PRINCIPLES OF TEAM BUILDING
THE POWER PRINCIPLES OF TEAM BUILDING
 
Collection Development a la Carte v.2
Collection Development a la Carte v.2Collection Development a la Carte v.2
Collection Development a la Carte v.2
 

Ähnlich wie Dti2143 chapter 3 arithmatic relation-logicalexpression

C programming session 02
C programming session 02C programming session 02
C programming session 02
Dushmanta Nath
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
rinkugupta37
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
rohassanie
 

Ähnlich wie Dti2143 chapter 3 arithmatic relation-logicalexpression (20)

Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Theory3
Theory3Theory3
Theory3
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
C - programming - Ankit Kumar Singh
C - programming - Ankit Kumar Singh C - programming - Ankit Kumar Singh
C - programming - Ankit Kumar Singh
 
additional.pptx
additional.pptxadditional.pptx
additional.pptx
 
3306617
33066173306617
3306617
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
Operators-computer programming and utilzation
Operators-computer programming and utilzationOperators-computer programming and utilzation
Operators-computer programming and utilzation
 
Lecture 6 operators
Lecture 6   operatorsLecture 6   operators
Lecture 6 operators
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
pointers 1
pointers 1pointers 1
pointers 1
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operators
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
C++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdfC++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdf
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
 
901131 examples
901131 examples901131 examples
901131 examples
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
 

Mehr von alish sha

It 302 computerized accounting (week 2) - sharifah
It 302   computerized accounting (week 2) - sharifahIt 302   computerized accounting (week 2) - sharifah
It 302 computerized accounting (week 2) - sharifah
alish sha
 
Lab 9 sem ii_12_13
Lab 9 sem ii_12_13Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
alish sha
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
alish sha
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012
alish sha
 
Purpose elaborate
Purpose elaboratePurpose elaborate
Purpose elaborate
alish sha
 
Lab sheet 1
Lab sheet 1Lab sheet 1
Lab sheet 1
alish sha
 
Test 1 alish schema 1
Test 1 alish schema 1Test 1 alish schema 1
Test 1 alish schema 1
alish sha
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
alish sha
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
alish sha
 
Final project
Final projectFinal project
Final project
alish sha
 
Final project
Final projectFinal project
Final project
alish sha
 
Attn list test
Attn list testAttn list test
Attn list test
alish sha
 
Carry markdam31303
Carry markdam31303Carry markdam31303
Carry markdam31303
alish sha
 

Mehr von alish sha (20)

T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9
 
July 2014 theory exam (theory)
July 2014 theory exam (theory)July 2014 theory exam (theory)
July 2014 theory exam (theory)
 
Accounting basic equation
Accounting basic equation Accounting basic equation
Accounting basic equation
 
It 302 computerized accounting (week 2) - sharifah
It 302   computerized accounting (week 2) - sharifahIt 302   computerized accounting (week 2) - sharifah
It 302 computerized accounting (week 2) - sharifah
 
It 302 computerized accounting (week 1) - sharifah
It 302   computerized accounting (week 1) - sharifahIt 302   computerized accounting (week 1) - sharifah
It 302 computerized accounting (week 1) - sharifah
 
What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)
 
Lab 9 sem ii_12_13
Lab 9 sem ii_12_13Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
 
Lab 6
Lab 6Lab 6
Lab 6
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012
 
Purpose elaborate
Purpose elaboratePurpose elaborate
Purpose elaborate
 
Lab sheet 1
Lab sheet 1Lab sheet 1
Lab sheet 1
 
Test 1 alish schema 1
Test 1 alish schema 1Test 1 alish schema 1
Test 1 alish schema 1
 
Lab 6 sem ii_11_12
Lab 6 sem ii_11_12Lab 6 sem ii_11_12
Lab 6 sem ii_11_12
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
 
Final project
Final projectFinal project
Final project
 
Final project
Final projectFinal project
Final project
 
Attn list test
Attn list testAttn list test
Attn list test
 
Carry markdam31303
Carry markdam31303Carry markdam31303
Carry markdam31303
 

KĂŒrzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

KĂŒrzlich hochgeladen (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Dti2143 chapter 3 arithmatic relation-logicalexpression

  • 1. DTI2143 Computer Programming 1 Chapter 3 Expression & Operators
  • 2.
  • 3.
  • 4. 4 Introduction to Expression Process involves in money withdrawal scenario balance – withdrawed money = current balance Expression in C : bakiTerkini =wangKeluar – bakiSemasa;
  • 5. What is Expression? 5 Introduction to Expression Combination or more than one variable or Constant (operand) which separated by operator Expression Operator example x + 3 - z Operand Consists of arithmetic relational logical
  • 6. 6 Arithmetic Expression Known as Arithmetic Expression Mathematic Expression using Arithmetic Operator Represents by Represents by Unary operator Binary operator
  • 7. Unary Operator 7 Arithmetic Expression Unary Operator Operates for one operand Computer memory cell example -20 a = -20; a b = +15; b +15
  • 8. Unary Operator 8 Arithmetic Expression Example 1: int A = 5; ++A; printf(“%d”, A); output ? A--; printf(“%d”,A); output ? A++; printf(“%d”,A); output ?
  • 9. Unary Operator 9 Arithmetic Expression Example 2: int A ; A=6; printf(“%d”,3 + --A); output ? printf(“%d”, A); output ? A=6; printf(“%d”, 3 + A--); output ? printf(“%d”, A); output ?
  • 10. Unary Operator 10 Arithmetic Expression Example 3: Given the value of num1 = 8 .Determine the value of num2 after the execution for each of the following statements: num2 = num1++ - 2; num2 = num1; num2 = ++num1 – 3; num2 = num1-- +1;
  • 11. 11
  • 12. Binary Operator 12 Arithmetic Expression Located between constants or variables or both combination Binary Operator example A+ z operator operand
  • 13. Binary Operator 13 Arithmetic Expression Multiplication Use symbol “ * ” example A * z operator operand Mathematic Arithmetic Expression 2x + y 2 * x + y
  • 14. Binary Operator 14 Arithmetic Expression Divide Use symbol “/” example A / z operator operand Mathematic Arithmetic Expression 2 : y 2 / y
  • 15. Binary Operator 15 Arithmetic Expression Modulus Use symbol “%” example A % z operator operand Return a balance when 2 numbers is divided Can only be used with an integer variable
  • 16. Binary Operator 16 Arithmetic Expression Example: int A, B; float C; A= 2; B= 5; C= 2.4; B% A; C % A; Valid! Answer is 1 Invalid! C is float
  • 17.
  • 18. Use operator symbol =Assignment statement Double assignment statement Compound assignment statement
  • 19.
  • 20.
  • 21. Example :int a = b= c = d = e = 250; int b =2, number =0, total = 0,average =3; number = b++ = 10; int age = workHour = 0;
  • 22.
  • 24. Original function of operator does not affected
  • 25. Allowed combination are as follow:operator: += , -= , *= , /= , %=
  • 26. Compound Assignment Statement 21 Arithmetic Expression Example :
  • 27. Arithmetic Operator Precedence Rules 22 Arithmetic Expression Compiler will follows the following precedence to execute the arithmetic expression based on priority.
  • 28. Arithmetic Operator Precedence Rules 23 Arithmetic Operator Example: 5 + 2 * 6 – 4 / 2 5 + 12 - 4 / 2 5 + 12 - 2 17 - 2 15 2. 3 * 4 / 2 + ( 3 –1) 3 * 4 / 2 + 2 12 / 2 + 2 6 + 2 8
  • 29. Arithmetic Operator Precedence Rules 24 Arithmetic Expression Example: 3. Prefix unary arithmetic expression intkira = 5, nilaipertama = 10; nilai_kedua = 5 * --kira + nilai_pertama; printf(“%d %d”, kira, nilai_kedua); Output: 4 30
  • 30. Arithmetic Operator Precedence Rules 25 Arithmetic Expression Example: 3. Prefix unary arithmetic expression int kira = 5, nilai pertama = 10; nilai_kedua = 5 * kira-- + nilai_pertama; printf(“%d %d”, kira, nilai_kedua); Output: 4 35
  • 31.
  • 33.
  • 34. Exercise: 28 Arithmetic Expression Convert the following mathematic expression to a valid arithmetic expression : a) b = 3 + bb) x = (a – b)(a – c2) a + 4 c) d = (3e – d) - ( 4 – 3c3 ) d) r = 2s + 3(s – 9) x – 9 4y s Given a= 3, b = 5, c=1. What is the output of the following expression? a. ( 6 * c – 6 / a) - b b. (5 * c) +( a* b / b) c. ++a d. c + a * c / (3 * c)
  • 35. Exercise: 29 Arithmetic Expression Assume i,j and k are integer variables with i = 5 and j=3. Determine what is the value for each of the following statement: a) k = j++; d) k = ++j; b) k = i * j--; e) k = i * --j; c) k = j + i * j++; f) k = 27 / j++ - 16 % i;
  • 36. 30 Relation Expression Relational expression use Relational operator Combination of more than one statement variable vs variable Can consists of variable vs constant produce constant vs constant 0 (if false) 1(if true)
  • 37. Relational Operator 31 Relation Expression
  • 38. 32 Relation Expression P/s: a, b and c are variables, Replace with the given values Example 1: int a=6, b =1, c = -2; a+ b == c 2) a != b 6 + 1== -2 6 != 1 7 == -2 Answer: 0(False) Answer : 1 (True)
  • 39. 33 Relation Expression Example 2 : int a=6, b =1, c = -2; 3) b < a 4) b + c <= a 1 < -2 1 + -2 < 6 -1 < 6 Answer: 0 (False) Answer : 1 (True)
  • 40. 34 Relation Expression P/s: Relational operator has less priority than other operators. Start evaluating from left to right. Example 3: int a=10, b = 3, c = 7; (a+b >= 3*c)==( a != 2*c+b) (10+3 >= 3*7)==(a != 2*c+b) (13 >= 21)==(10 != 14+3) (13 >= 21)==(10 != 17) 0 == 1 0 (false)
  • 41. 35 Relation Expression An example program which uses relational expression #include <stdio.h> void main() { int age; printf(“Please enter your age >>”); scanf(“%d”,&age); if (age > 21) printf(“You are qualified to vote”); } Relational expression
  • 42. 36 Logical Expression Logical Operator Logical expression use Combination of one or more expressions Can consists of Relational expr. vs logical expr. Relational expr. vs variable produces Relational expr. vs constant 0 (if false) 1(if true)
  • 43. 37 Logical Expression Logical Operator Logical operator && dan || is used between 2 or more relational expression
  • 44. 38 Logical Expression Logical operator truth table for AND AND (&&)
  • 45. 39 Logical Expression Logical operator truth table for OR OR (||)
  • 46. 40 Logical Expression Logical operator truth table for NOT NOT(!)
  • 47. 41 Logical Expression Example 1: Evaluate the following logical expression: (2 < 5 ) && ( 5 < 10) b) (7 % 2 < 2) || ( 2 * 3 == 6) 1 && 1 (1 < 2) || (6 == 6) 1 1 || 1 1
  • 48. 42 Logical Expression Example 2: Evaluate the following logical expression: Given a = 3, b = 4; c) !((5 * b <= 23 - a )) d) ! ((b +3 != 8) &&( 3 * a < 2)) !((5 * 4 <= 23 – 3)) !(( 7 != 8 ) && ( 9 < 2 )) !(20 <= 20) ! ( 1 && 0 ) !(1) ! ( 0) 0 1
  • 49. 43 Logical Expression Logical Expression An example program which using Logical Expression: #include <stdio.h> void main() { int mark; printf(“Enter your mark >>”); scanf(“%d”,&mark); if (mark >= 85 && mark <= 100) printf(“Gred A”); else if( mark >=80 && mark <=84) printf(“Gred A-”); }
  • 50. Exercise: 44 Logical Expression Given with i=2, j = 5 and k = 15. Evaluate each of the following expression: a) i > j – k g) k == j + I * j b) i != k h) k <=k /j c) (i >= 1) && (j == 5) i) (j < i) || (k > j) d) !( i > j) j) (i >0) && (j <k) || (k <i) e) i < j < k k) i * k < k / j f) (i < j) && (j < k) i) i – j > k Complete the following statements with suitable logical expression. int angka1,angka2; if (angka1 is less than or equal to angka2) printf(“%d is less than or equal to %d”,angka1,angka2);