SlideShare uma empresa Scribd logo
1 de 7
Baixar para ler offline
CS111 Lab
Arithmetic
Instructor: Michael Gordon
C++ Arithmetic Operators
 + Addition
 - Subtraction
 * Multiplication
 / Division
 % Modulus (remainder)
 () Parentheses
Order of Operations
 ()
 * / %
 + -
 (4 + 2) / 2 + 4 = ???
 Operation in () first: 4+2=6
 Division next: 6 / 2 = 3
 Last addition, 3 + 4 = 7
Integer and Decimal Division
 Division of two integers drops the decimal:
 5 / 2 = 2 (not 2.5)
 4 / 2 = 2
 Division involving a double type, will result
in a double result (with decimal)
 5 / 2.0 = 2.5
 4 / 2.0 = 2
 One or both numbers must be a double
 Same rules apply to addition, subtraction
and multiplication.
Data Types and Order
 Sample operations and resulting data
types:
 6.0 + 5 / 2
 Result of first operation: int
 Result of second operation: double
 • 5 + 5 / 2.0
 Result of first operation: double
 Result of second operation: double
Type casting
 Type casting changes one type to
another.
 For example if you want a double type
result of integer division, you can do this:
 double result = (double) 5 / 2
 result now equals 2.5
Type casting
 Reverse example (double to int)
 Drops the decimal part
 double total = 100.5;
 int value = (int) total;
 value now equals 100.

Mais conteúdo relacionado

Mais procurados

Sept. 21, 2012
Sept. 21, 2012Sept. 21, 2012
Sept. 21, 2012
khyps13
 
5 5b Slope Intercept Form from Two Points
5 5b Slope Intercept Form from Two Points5 5b Slope Intercept Form from Two Points
5 5b Slope Intercept Form from Two Points
Bitsy Griffin
 
Linear Programming Project
Linear Programming ProjectLinear Programming Project
Linear Programming Project
Chawal Ukesh
 

Mais procurados (19)

Quantitative Analysis For Decision Making
Quantitative Analysis For Decision MakingQuantitative Analysis For Decision Making
Quantitative Analysis For Decision Making
 
Order of Operations
Order of OperationsOrder of Operations
Order of Operations
 
Sept. 21, 2012
Sept. 21, 2012Sept. 21, 2012
Sept. 21, 2012
 
Assignment Problem
Assignment ProblemAssignment Problem
Assignment Problem
 
Survey On Two-Term Dot Product Of Multiplier Using Floating Point
Survey On Two-Term Dot Product Of Multiplier Using Floating PointSurvey On Two-Term Dot Product Of Multiplier Using Floating Point
Survey On Two-Term Dot Product Of Multiplier Using Floating Point
 
Solving one step equations (workshop 1)
Solving one step equations (workshop 1)Solving one step equations (workshop 1)
Solving one step equations (workshop 1)
 
Chapter 7 Formats in MATLAB
Chapter 7 Formats in MATLABChapter 7 Formats in MATLAB
Chapter 7 Formats in MATLAB
 
Mathematichs
MathematichsMathematichs
Mathematichs
 
Assignment Problem
Assignment ProblemAssignment Problem
Assignment Problem
 
Inequalities
InequalitiesInequalities
Inequalities
 
Fantacy foot ball introduction
Fantacy foot ball introductionFantacy foot ball introduction
Fantacy foot ball introduction
 
Powers and Exponents.pptx
Powers and Exponents.pptxPowers and Exponents.pptx
Powers and Exponents.pptx
 
5 5b Slope Intercept Form from Two Points
5 5b Slope Intercept Form from Two Points5 5b Slope Intercept Form from Two Points
5 5b Slope Intercept Form from Two Points
 
Add and Subtract Decimals
Add and Subtract DecimalsAdd and Subtract Decimals
Add and Subtract Decimals
 
Linear Programming Project
Linear Programming ProjectLinear Programming Project
Linear Programming Project
 
Untitled 2
Untitled 2Untitled 2
Untitled 2
 
DIVISION: TWO-DIGIT DIVISOR
DIVISION: TWO-DIGIT DIVISORDIVISION: TWO-DIGIT DIVISOR
DIVISION: TWO-DIGIT DIVISOR
 
Lesson 33: The Assignment Problem
Lesson 33: The Assignment  ProblemLesson 33: The Assignment  Problem
Lesson 33: The Assignment Problem
 
Fractions
FractionsFractions
Fractions
 

Destaque (7)

2010 1st sem_course_module_hotel_accountancy.2010
2010 1st  sem_course_module_hotel_accountancy.20102010 1st  sem_course_module_hotel_accountancy.2010
2010 1st sem_course_module_hotel_accountancy.2010
 
What's Next for Western Europe
What's Next for Western EuropeWhat's Next for Western Europe
What's Next for Western Europe
 
Recyclingandjobsinmassachusetts
RecyclingandjobsinmassachusettsRecyclingandjobsinmassachusetts
Recyclingandjobsinmassachusetts
 
Smp presentation incl videos 1g
Smp presentation incl videos 1gSmp presentation incl videos 1g
Smp presentation incl videos 1g
 
Difan Zhang IMC project
Difan Zhang IMC projectDifan Zhang IMC project
Difan Zhang IMC project
 
The Green Roundtable Brings it All Together at NEXUS Green Resource Center
The Green Roundtable Brings it All Together at NEXUS Green Resource CenterThe Green Roundtable Brings it All Together at NEXUS Green Resource Center
The Green Roundtable Brings it All Together at NEXUS Green Resource Center
 
10 million solar roofs act of 2011
10 million solar roofs act of 201110 million solar roofs act of 2011
10 million solar roofs act of 2011
 

Semelhante a Arithmetic

Adding and subtracting
Adding and subtractingAdding and subtracting
Adding and subtracting
Diana Pineda
 
Thursday, september 26, 2013
Thursday, september 26, 2013Thursday, september 26, 2013
Thursday, september 26, 2013
khyps13
 
1 arithmetic
1 arithmetic1 arithmetic
1 arithmetic
fyjordan9
 
11414 2.3 Homework (Quadratic Equations)courses.thinkwel.docx
11414 2.3 Homework (Quadratic Equations)courses.thinkwel.docx11414 2.3 Homework (Quadratic Equations)courses.thinkwel.docx
11414 2.3 Homework (Quadratic Equations)courses.thinkwel.docx
hyacinthshackley2629
 
3 Performing Mensuration and Calculation.pptx
3 Performing  Mensuration and Calculation.pptx3 Performing  Mensuration and Calculation.pptx
3 Performing Mensuration and Calculation.pptx
GemDL
 

Semelhante a Arithmetic (20)

Adding and subtracting
Adding and subtractingAdding and subtracting
Adding and subtracting
 
Thursday, september 26, 2013
Thursday, september 26, 2013Thursday, september 26, 2013
Thursday, september 26, 2013
 
Ch02 primitive-data-definite-loops
Ch02 primitive-data-definite-loopsCh02 primitive-data-definite-loops
Ch02 primitive-data-definite-loops
 
1 arithmetic
1 arithmetic1 arithmetic
1 arithmetic
 
CST2403 NOTES
CST2403 NOTESCST2403 NOTES
CST2403 NOTES
 
For Loops and Variables in Java
For Loops and Variables in JavaFor Loops and Variables in Java
For Loops and Variables in Java
 
divisibilitytheory_2042918529272231.pptx
divisibilitytheory_2042918529272231.pptxdivisibilitytheory_2042918529272231.pptx
divisibilitytheory_2042918529272231.pptx
 
Difference of Two Squares
Difference of Two SquaresDifference of Two Squares
Difference of Two Squares
 
Facility Layout in production management
Facility Layout in production managementFacility Layout in production management
Facility Layout in production management
 
Data type
Data typeData type
Data type
 
2 data 2011
2 data 20112 data 2011
2 data 2011
 
order of operations
order of operationsorder of operations
order of operations
 
coefficient variation
coefficient variationcoefficient variation
coefficient variation
 
Oop project
Oop projectOop project
Oop project
 
Civil Service Review in Math.pptx
Civil Service Review in Math.pptxCivil Service Review in Math.pptx
Civil Service Review in Math.pptx
 
11414 2.3 Homework (Quadratic Equations)courses.thinkwel.docx
11414 2.3 Homework (Quadratic Equations)courses.thinkwel.docx11414 2.3 Homework (Quadratic Equations)courses.thinkwel.docx
11414 2.3 Homework (Quadratic Equations)courses.thinkwel.docx
 
3 Performing Mensuration and Calculation.pptx
3 Performing  Mensuration and Calculation.pptx3 Performing  Mensuration and Calculation.pptx
3 Performing Mensuration and Calculation.pptx
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
 
Polynomial Operations
Polynomial OperationsPolynomial Operations
Polynomial Operations
 
09.30.2019 to 10.03.2019 Polynomials Algebra111 I.pptx
09.30.2019 to 10.03.2019 Polynomials Algebra111 I.pptx09.30.2019 to 10.03.2019 Polynomials Algebra111 I.pptx
09.30.2019 to 10.03.2019 Polynomials Algebra111 I.pptx
 

Mais de Michael Gordon (18)

Raspberry Pi presentation for Computer Architecture class
Raspberry Pi presentation for Computer Architecture classRaspberry Pi presentation for Computer Architecture class
Raspberry Pi presentation for Computer Architecture class
 
Strings2
Strings2Strings2
Strings2
 
Strings1
Strings1Strings1
Strings1
 
Introduction to Computer Science 111 Lab
Introduction to Computer Science 111 LabIntroduction to Computer Science 111 Lab
Introduction to Computer Science 111 Lab
 
Introduction to Linux, Pico, G++
Introduction to Linux, Pico, G++Introduction to Linux, Pico, G++
Introduction to Linux, Pico, G++
 
Strings
StringsStrings
Strings
 
Arrays, continued
Arrays, continuedArrays, continued
Arrays, continued
 
Arrays
ArraysArrays
Arrays
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Functions
FunctionsFunctions
Functions
 
Shape logic 1
Shape logic 1Shape logic 1
Shape logic 1
 
For loops
For loopsFor loops
For loops
 
While loops
While loopsWhile loops
While loops
 
If statements
If statementsIf statements
If statements
 
Variables
VariablesVariables
Variables
 
Output
OutputOutput
Output
 
Word cloud
Word cloudWord cloud
Word cloud
 
Millennial white paper
Millennial white paperMillennial white paper
Millennial white paper
 

Último

Future of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot ReportFuture of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Dubai Multi Commodity Centre
 
Presentation4 (2) survey responses clearly labelled
Presentation4 (2) survey responses clearly labelledPresentation4 (2) survey responses clearly labelled
Presentation4 (2) survey responses clearly labelled
CaitlinCummins3
 
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
prakheeshc
 
#Mtp-Kit Prices » Qatar. Doha (+27737758557) Abortion Pills For Sale In Doha,...
#Mtp-Kit Prices » Qatar. Doha (+27737758557) Abortion Pills For Sale In Doha,...#Mtp-Kit Prices » Qatar. Doha (+27737758557) Abortion Pills For Sale In Doha,...
#Mtp-Kit Prices » Qatar. Doha (+27737758557) Abortion Pills For Sale In Doha,...
drm1699
 
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di PasuruanObat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Jakarta Wa 085176963835 Apotek Jual Obat Cytotec Di Jakarta
 

Último (20)

Future of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot ReportFuture of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
 
stock price prediction using machine learning
stock price prediction using machine learningstock price prediction using machine learning
stock price prediction using machine learning
 
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deck
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deckPitch Deck Teardown: Goodcarbon's $5.5m Seed deck
Pitch Deck Teardown: Goodcarbon's $5.5m Seed deck
 
How Bookkeeping helps you in Cost Saving, Tax Saving and Smooth Business Runn...
How Bookkeeping helps you in Cost Saving, Tax Saving and Smooth Business Runn...How Bookkeeping helps you in Cost Saving, Tax Saving and Smooth Business Runn...
How Bookkeeping helps you in Cost Saving, Tax Saving and Smooth Business Runn...
 
How to refresh to be fit for the future world
How to refresh to be fit for the future worldHow to refresh to be fit for the future world
How to refresh to be fit for the future world
 
Stages of Startup Funding - An Explainer
Stages of Startup Funding - An ExplainerStages of Startup Funding - An Explainer
Stages of Startup Funding - An Explainer
 
WAM Corporate Presentation May 2024_w.pdf
WAM Corporate Presentation May 2024_w.pdfWAM Corporate Presentation May 2024_w.pdf
WAM Corporate Presentation May 2024_w.pdf
 
Presentation4 (2) survey responses clearly labelled
Presentation4 (2) survey responses clearly labelledPresentation4 (2) survey responses clearly labelled
Presentation4 (2) survey responses clearly labelled
 
Pay after result spell caster (,$+27834335081)@ bring back lost lover same da...
Pay after result spell caster (,$+27834335081)@ bring back lost lover same da...Pay after result spell caster (,$+27834335081)@ bring back lost lover same da...
Pay after result spell caster (,$+27834335081)@ bring back lost lover same da...
 
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
 
Hyundai capital 2024 1q Earnings release
Hyundai capital 2024 1q Earnings releaseHyundai capital 2024 1q Earnings release
Hyundai capital 2024 1q Earnings release
 
How Do Venture Capitalists Make Decisions?
How Do Venture Capitalists Make Decisions?How Do Venture Capitalists Make Decisions?
How Do Venture Capitalists Make Decisions?
 
Top^Clinic ^%[+27785538335__Safe*Women's clinic//Abortion Pills In Harare
Top^Clinic ^%[+27785538335__Safe*Women's clinic//Abortion Pills In HarareTop^Clinic ^%[+27785538335__Safe*Women's clinic//Abortion Pills In Harare
Top^Clinic ^%[+27785538335__Safe*Women's clinic//Abortion Pills In Harare
 
Exploring-Pipe-Flanges-Applications-Types-and-Benefits.pptx
Exploring-Pipe-Flanges-Applications-Types-and-Benefits.pptxExploring-Pipe-Flanges-Applications-Types-and-Benefits.pptx
Exploring-Pipe-Flanges-Applications-Types-and-Benefits.pptx
 
Series A Fundraising Guide (Investing Individuals Improving Our World) by Accion
Series A Fundraising Guide (Investing Individuals Improving Our World) by AccionSeries A Fundraising Guide (Investing Individuals Improving Our World) by Accion
Series A Fundraising Guide (Investing Individuals Improving Our World) by Accion
 
#Mtp-Kit Prices » Qatar. Doha (+27737758557) Abortion Pills For Sale In Doha,...
#Mtp-Kit Prices » Qatar. Doha (+27737758557) Abortion Pills For Sale In Doha,...#Mtp-Kit Prices » Qatar. Doha (+27737758557) Abortion Pills For Sale In Doha,...
#Mtp-Kit Prices » Qatar. Doha (+27737758557) Abortion Pills For Sale In Doha,...
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
Daftar Rumpun, Pohon, dan Cabang Ilmu (2024).pdf
Daftar Rumpun, Pohon, dan Cabang Ilmu (2024).pdfDaftar Rumpun, Pohon, dan Cabang Ilmu (2024).pdf
Daftar Rumpun, Pohon, dan Cabang Ilmu (2024).pdf
 
Navigating Tax Season with Confidence Streamlines CPA Firms
Navigating Tax Season with Confidence Streamlines CPA FirmsNavigating Tax Season with Confidence Streamlines CPA Firms
Navigating Tax Season with Confidence Streamlines CPA Firms
 
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di PasuruanObat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
 

Arithmetic

  • 2. C++ Arithmetic Operators  + Addition  - Subtraction  * Multiplication  / Division  % Modulus (remainder)  () Parentheses
  • 3. Order of Operations  ()  * / %  + -  (4 + 2) / 2 + 4 = ???  Operation in () first: 4+2=6  Division next: 6 / 2 = 3  Last addition, 3 + 4 = 7
  • 4. Integer and Decimal Division  Division of two integers drops the decimal:  5 / 2 = 2 (not 2.5)  4 / 2 = 2  Division involving a double type, will result in a double result (with decimal)  5 / 2.0 = 2.5  4 / 2.0 = 2  One or both numbers must be a double  Same rules apply to addition, subtraction and multiplication.
  • 5. Data Types and Order  Sample operations and resulting data types:  6.0 + 5 / 2  Result of first operation: int  Result of second operation: double  • 5 + 5 / 2.0  Result of first operation: double  Result of second operation: double
  • 6. Type casting  Type casting changes one type to another.  For example if you want a double type result of integer division, you can do this:  double result = (double) 5 / 2  result now equals 2.5
  • 7. Type casting  Reverse example (double to int)  Drops the decimal part  double total = 100.5;  int value = (int) total;  value now equals 100.