SlideShare a Scribd company logo
Arithmetic In C 
Computer Science: A Structured Programming Approach Using C 1
Arithmetic In C 
To solve most programming problems, you need to write 
arithmetic operations that manipulate type integer, float and 
double data. 
C enables programmers to perform all types of arithmetic 
calculations. Most common used arithmetic operators are: 
Computer Science: A Structured Programming Approach Using C 2
Computer Science: A Structured Programming Approach Using C 3
Expression 
•An expression is a sequence of operands and 
operators that reduces to a single value. 
Expressions can be simple or complex. 
•An operator is a syntactical token that requires an 
action be taken. 
•An operand is an object on which an operation is 
performed; it receives an operator’s action. 
Computer Science: A Structured Programming Approach Using C 4
Expression 
Result = Operand1 + Operand2 
The equal sign (=) is an assignment operator where 
the right side is being assigned to the left side of the 
operator (=) . 
Computer Science: A Structured Programming Approach Using C 5
Both operands of the modulus operator (%) must 
be integer types. 
Note 
Computer Science: A Structured Programming Approach Using C 6
Computer Science: A Structured Programming Approach Using C 7
Computer Science: A Structured Programming Approach Using C 8
Computer Science: A Structured Programming Approach Using C 9
Converting Algebra Formulas 
To C Formulas 
•Always specify multiplication with the symbol *. 
•C explicitly require the multiplication operator. 
Example: a*b ( cannot put it as ab ) 
•Use parentheses when required to control the 
order of operator evaluation. 
Computer Science: A Structured Programming Approach Using C 10
Converting Algebra Formulas 
To C Formulas 
Computer Science: A Structured Programming Approach Using C 11
Precedence and Associativity 
•Precedence is used to determine the order in which 
different operators in a complex expression are 
evaluated. 
•Associativity is used to determine the order in which 
operators with the same precedence are evaluated in a 
complex expression. 
Left-to-Right Associativity 
Computer Science: A Structured Programming Approach Using C 12
Computer Science: A Structured Programming Approach Using C 13
Computer Science: A Structured Programming Approach Using C 14
Expression Evaluation 
Computer Science: A Structured Programming Approach Using C 15
Expression Evaluation 
Computer Science: A Structured Programming Approach Using C 16
Expression Evaluation 
Computer Science: A Structured Programming Approach Using C 17
Compound Expression 
Compound 
Expression 
Equivalent Simple 
Expression 
X*=3 X=X*3 
X/=3 X=X/3 
X%=3 X=X%3 
X+=1 X=X+1 
X-=1 X=X-1 
Computer Science: A Structured Programming Approach Using C 18
Increment and Decrement Operator 
Increment Decrement 
Prefix Increment Postfix Increment Prefix Decrement Postfix Decrement 
++a a++ --a a-- 
Increment a by 1 
then use the new 
value of a in the 
expression. 
Use the current 
value of a in the 
expression, then 
increment a by 1. 
Decrement a by 1 
then use the new 
value of a in the 
expression. 
Use the current 
value of a in the 
expression, then 
decrement a by 1. 
Computer Science: A Structured Programming Approach Using C 19
Demonstrate Postfix Increment 
Computer Science: A Structured Programming Approach Using C 20
Demonstrate Postfix Increment (continued) 
Computer Science: A Structured Programming Approach Using C 21
Demonstrate Prefix Increment 
Computer Science: A Structured Programming Approach Using C 22
Demonstrate Prefix Increment (continued) 
Computer Science: A Structured Programming Approach Using C 23
Evaluating Expressions 
Computer Science: A Structured Programming Approach Using C 24
Evaluating Expressions 
Computer Science: A Structured Programming Approach Using C 25
Evaluating Expressions 
Computer Science: A Structured Programming Approach Using C 26

More Related Content

What's hot

Lesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th stepLesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th step
MLG College of Learning, Inc
 
Cs8261 cp lab syllabus
Cs8261 cp lab syllabusCs8261 cp lab syllabus
Cs8261 cp lab syllabus
Palani Chamy
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
Lesson 3.2 data types for memory location
Lesson 3.2 data types for memory locationLesson 3.2 data types for memory location
Lesson 3.2 data types for memory location
MLG College of Learning, Inc
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
Anuja Lad
 
C# operators
C# operatorsC# operators
Programming qns
Programming qnsProgramming qns
Programming qns
Dr.Subha Krishna
 
PF LAB ASSIGNMENT
PF LAB ASSIGNMENTPF LAB ASSIGNMENT
PF LAB ASSIGNMENT
minqadtahir
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
Manoj Tyagi
 
1 Anne complains that defining functions to use in her programs is a lot of ...
1 Anne complains that defining functions to use in her programs is a lot of  ...1 Anne complains that defining functions to use in her programs is a lot of  ...
1 Anne complains that defining functions to use in her programs is a lot of ...
hwbloom59
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
Aswin Pv
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
Md Masudur Rahman
 
Relational operators In C language (By: Shujaat Abbas)
Relational operators In C language (By: Shujaat Abbas)Relational operators In C language (By: Shujaat Abbas)
Relational operators In C language (By: Shujaat Abbas)
Shujaat Abbas
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
AnkitaSharma463389
 
3. user input and some basic problem
3. user input and some basic problem3. user input and some basic problem
3. user input and some basic problem
Alamgir Hossain
 
Assignment9
Assignment9Assignment9
Assignment9
Sunita Milind Dol
 
Conversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad balochConversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad baloch
Sarmad Baloch
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
Asheesh kushwaha
 

What's hot (20)

Lesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th stepLesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th step
 
Cs8261 cp lab syllabus
Cs8261 cp lab syllabusCs8261 cp lab syllabus
Cs8261 cp lab syllabus
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
 
Lesson 3.2 data types for memory location
Lesson 3.2 data types for memory locationLesson 3.2 data types for memory location
Lesson 3.2 data types for memory location
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
C# operators
C# operatorsC# operators
C# operators
 
Programming qns
Programming qnsProgramming qns
Programming qns
 
PF LAB ASSIGNMENT
PF LAB ASSIGNMENTPF LAB ASSIGNMENT
PF LAB ASSIGNMENT
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Prefix Postfix
Prefix PostfixPrefix Postfix
Prefix Postfix
 
1 Anne complains that defining functions to use in her programs is a lot of ...
1 Anne complains that defining functions to use in her programs is a lot of  ...1 Anne complains that defining functions to use in her programs is a lot of  ...
1 Anne complains that defining functions to use in her programs is a lot of ...
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Relational operators In C language (By: Shujaat Abbas)
Relational operators In C language (By: Shujaat Abbas)Relational operators In C language (By: Shujaat Abbas)
Relational operators In C language (By: Shujaat Abbas)
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
3. user input and some basic problem
3. user input and some basic problem3. user input and some basic problem
3. user input and some basic problem
 
Assignment9
Assignment9Assignment9
Assignment9
 
Conversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad balochConversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad baloch
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 

Similar to test(3)arithmetic in c

Chap-03-1.ppt
Chap-03-1.pptChap-03-1.ppt
Chap-03-1.ppt
ShraddhaPattnaik
 
intro to differnt oper.pptx
intro to differnt oper.pptxintro to differnt oper.pptx
intro to differnt oper.pptx
ssuser5ad1571
 
Chap-14-1 (1).ppt
Chap-14-1 (1).pptChap-14-1 (1).ppt
Chap-14-1 (1).ppt
OmPrakasDas
 
Chapter 02-02.pptx
Chapter 02-02.pptxChapter 02-02.pptx
Chapter 02-02.pptx
ssuser5ad1571
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
madihamaqbool6
 
Chap-02-01.ppt
Chap-02-01.pptChap-02-01.ppt
Chap-02-01.ppt
ssuser5ad1571
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
Vamshi171
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
ShraddhaPattnaik
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
UdhayaKumar175069
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
hamsa72
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
ssusere6f5a11
 
Chap 02-1
Chap 02-1Chap 02-1
Chap 02-1
Navjot Singh
 
Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Computer programming chapter ( 4 )
Computer programming chapter ( 4 )
Ibrahim Elewah
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
Terry Yoast
 
C basics
C basicsC basics
C basics
sridevi5983
 
C basics
C basicsC basics
C basics
sridevi5983
 
C programming
C programmingC programming
C programming
Rounak Samdadia
 
C program
C programC program
C program
AJAL A J
 

Similar to test(3)arithmetic in c (20)

Chap-03-1.ppt
Chap-03-1.pptChap-03-1.ppt
Chap-03-1.ppt
 
intro to differnt oper.pptx
intro to differnt oper.pptxintro to differnt oper.pptx
intro to differnt oper.pptx
 
Chap-14-1 (1).ppt
Chap-14-1 (1).pptChap-14-1 (1).ppt
Chap-14-1 (1).ppt
 
Chapter 02-02.pptx
Chapter 02-02.pptxChapter 02-02.pptx
Chapter 02-02.pptx
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
 
Chapter 4 5
Chapter 4 5Chapter 4 5
Chapter 4 5
 
Chap-02-01.ppt
Chap-02-01.pptChap-02-01.ppt
Chap-02-01.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
C programming-1.pptx
C programming-1.pptxC programming-1.pptx
C programming-1.pptx
 
Chap-02-1.ppt
Chap-02-1.pptChap-02-1.ppt
Chap-02-1.ppt
 
Chap 02-1
Chap 02-1Chap 02-1
Chap 02-1
 
Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Computer programming chapter ( 4 )
Computer programming chapter ( 4 )
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
 
C basics
C basicsC basics
C basics
 
C basics
C basicsC basics
C basics
 
C programming
C programmingC programming
C programming
 
C program
C programC program
C program
 

Recently uploaded

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

test(3)arithmetic in c

  • 1. Arithmetic In C Computer Science: A Structured Programming Approach Using C 1
  • 2. Arithmetic In C To solve most programming problems, you need to write arithmetic operations that manipulate type integer, float and double data. C enables programmers to perform all types of arithmetic calculations. Most common used arithmetic operators are: Computer Science: A Structured Programming Approach Using C 2
  • 3. Computer Science: A Structured Programming Approach Using C 3
  • 4. Expression •An expression is a sequence of operands and operators that reduces to a single value. Expressions can be simple or complex. •An operator is a syntactical token that requires an action be taken. •An operand is an object on which an operation is performed; it receives an operator’s action. Computer Science: A Structured Programming Approach Using C 4
  • 5. Expression Result = Operand1 + Operand2 The equal sign (=) is an assignment operator where the right side is being assigned to the left side of the operator (=) . Computer Science: A Structured Programming Approach Using C 5
  • 6. Both operands of the modulus operator (%) must be integer types. Note Computer Science: A Structured Programming Approach Using C 6
  • 7. Computer Science: A Structured Programming Approach Using C 7
  • 8. Computer Science: A Structured Programming Approach Using C 8
  • 9. Computer Science: A Structured Programming Approach Using C 9
  • 10. Converting Algebra Formulas To C Formulas •Always specify multiplication with the symbol *. •C explicitly require the multiplication operator. Example: a*b ( cannot put it as ab ) •Use parentheses when required to control the order of operator evaluation. Computer Science: A Structured Programming Approach Using C 10
  • 11. Converting Algebra Formulas To C Formulas Computer Science: A Structured Programming Approach Using C 11
  • 12. Precedence and Associativity •Precedence is used to determine the order in which different operators in a complex expression are evaluated. •Associativity is used to determine the order in which operators with the same precedence are evaluated in a complex expression. Left-to-Right Associativity Computer Science: A Structured Programming Approach Using C 12
  • 13. Computer Science: A Structured Programming Approach Using C 13
  • 14. Computer Science: A Structured Programming Approach Using C 14
  • 15. Expression Evaluation Computer Science: A Structured Programming Approach Using C 15
  • 16. Expression Evaluation Computer Science: A Structured Programming Approach Using C 16
  • 17. Expression Evaluation Computer Science: A Structured Programming Approach Using C 17
  • 18. Compound Expression Compound Expression Equivalent Simple Expression X*=3 X=X*3 X/=3 X=X/3 X%=3 X=X%3 X+=1 X=X+1 X-=1 X=X-1 Computer Science: A Structured Programming Approach Using C 18
  • 19. Increment and Decrement Operator Increment Decrement Prefix Increment Postfix Increment Prefix Decrement Postfix Decrement ++a a++ --a a-- Increment a by 1 then use the new value of a in the expression. Use the current value of a in the expression, then increment a by 1. Decrement a by 1 then use the new value of a in the expression. Use the current value of a in the expression, then decrement a by 1. Computer Science: A Structured Programming Approach Using C 19
  • 20. Demonstrate Postfix Increment Computer Science: A Structured Programming Approach Using C 20
  • 21. Demonstrate Postfix Increment (continued) Computer Science: A Structured Programming Approach Using C 21
  • 22. Demonstrate Prefix Increment Computer Science: A Structured Programming Approach Using C 22
  • 23. Demonstrate Prefix Increment (continued) Computer Science: A Structured Programming Approach Using C 23
  • 24. Evaluating Expressions Computer Science: A Structured Programming Approach Using C 24
  • 25. Evaluating Expressions Computer Science: A Structured Programming Approach Using C 25
  • 26. Evaluating Expressions Computer Science: A Structured Programming Approach Using C 26