Expressions and Arithmetic - PowerPoint PPT Presentation

About This Presentation
Title:

Expressions and Arithmetic

Description:

Expressions and Arithmetic – PowerPoint PPT presentation

Number of Views:11
Avg rating:3.0/5.0
Slides: 12
Provided by: David6
Category:

less

Transcript and Presenter's Notes

Title: Expressions and Arithmetic


1
Expressions and Arithmetic
2
Assignments
  • Due Lab 1
  • Reading Chapter 3 3.1-3.4

3
Precision
  • Describes number of columns to use when
    displaying number
  • 5.2 lf number is right-justified
  • -5.2lf number is left-justified
  • If number is too small minimum number of
    columns will be used
  • Decimal numbers are rounded
  • Decimal point occupies a column as does (for
    negative numbers)

4
Precision Example
  • include ltstdio.hgt int main(void)   
    double x 12345.6789      printf("10.2 -
    5.2lf\n", x)    printf("4.2 - 4.2lf\n", x)
       printf("5.6 - 5.6lf\n", x)    printf("15.6
    - 15.6lf\n", x)    printf("0.3 - 0.3lf\n",
    x)      return(0)

5
Precision Example
  • include ltstdio.hgt int main(void)   
    double x 12345.6789      printf("10.2 -
    5.2lf\n", x) //12345.68
  •    printf("4.2 - 4.2lf\n", x) //12345.68   
    printf("5.6 - 5.6lf\n", x) //12345.678900   
    printf("15.6 - 15.6lf\n", x) // 12345.678900
  •    printf("0.3 - 0.3lf\n", x) //12345.679  
       return(0)

6
Arithmetic Expressions
  • c a b
  • d 12/6
  • Binary Operators
  • -
  • /
  • Unary Operator
  • -

7
Examples
  • 10 8
  • 32 10
  • 55 11

8
Expression Type
  • Depends on operands
  • int int -gt int
  • double double -gt double
  • int double -gt double
  • int / int -gt ???

9
Precedence/Associativity
  • Parentheses
  • Unary operators
  • , /,
  • , - (binary)
  • Binary evaluated left to right

10
Assignment
  • total cost tax
  • sum sum item -gt sum item
  • mynum 5
  • mynum 12

11
Errors
  • Syntax
  • printf(Hello, World!)
  • Runtime
  • x 0
  • y 32/x
  • Logic
  • printf(Hell, World!)
Write a Comment
User Comments (0)
About PowerShow.com