SlideShare uma empresa Scribd logo
1 de 26
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

Mais conteúdo relacionado

Mais procurados

Cs8261 cp lab syllabus
Cs8261 cp lab syllabusCs8261 cp lab syllabus
Cs8261 cp lab syllabusPalani Chamy
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expressionDrkhanchanaR
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsAnuja Lad
 
PF LAB ASSIGNMENT
PF LAB ASSIGNMENTPF LAB ASSIGNMENT
PF LAB ASSIGNMENTminqadtahir
 
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 programmingManoj 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 operatorsAswin Pv
 
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
 
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 problemAlamgir Hossain
 
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 balochSarmad Baloch
 

Mais procurados (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
 

Semelhante a test(3)arithmetic in c

Semelhante a 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
 
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
 
C programming-1.pptx
C programming-1.pptxC programming-1.pptx
C programming-1.pptx
 
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
 

Último

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Último (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

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