Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic C Programming Data Types and Arithmetic Operations 01/30/15.

Similar presentations


Presentation on theme: "Basic C Programming Data Types and Arithmetic Operations 01/30/15."— Presentation transcript:

1 Basic C Programming Data Types and Arithmetic Operations 01/30/15

2 Objectives Know the basic data types in C. Use arithmetic operators in C. Tell what data type an expression has. Use output formats to display values. Declare and use variables. Use assignment statements to give variables values. Input values using scanf

3 Data Types Integer  int  char Floating Point  float  double

4 Integer Binary number with sign In memory: e.g. 100, 15, 0, -19, -100000 Precise Sign bit

5 Integer int Stores +/- counting numbers Stored as integer char – stores characters. Also stored as Integer Stores numeric codes for characters 'A', 'z', '1', '\n' More escape sequences on page 62. ASCII codes on pg. 61 How would “Cat” be stored?

6 Floating Point mantissaexponent In Memory: Number = mantissa x 2 exponent

7 Floating Point float e.g. 45.7, 8.97e-4, -15.4 – e-format ^ 8.97 x 10 -4 Not exact double is similar – Uses twice as much storage – Use when number needs to be more accurate or greater magnitude

8 Arithmetic Operators Math +, - (Unary) X,, /, ÷ +, - (Binary) x n C + - (Unary) *, /, % +, - (Binary) No exponent op

9 Expression Combination of operators and operands 85 22+6 7.5 / 2.5 + 3.0

10 Order of Operations 1. Parenthesis 2. Unary +, - 3. *, /, % 4. Binary +, - e.g. 4 + 2 * 5 5 * ( 14 + -7)

11 Expression Type Type of results is same as operands 5 + 4 --> int 9 1.3 * 2.0 --> double 3.5 Result of mixed operation is double type 5 + 1.2 --> double 6.2

12 What is the result of each? 6 + 18 / 2 1.2 * 3.0 5.0 * 9 3.0 * 0.1 + 1.5 * 2.0 4 * (9 + 1)

13 Integer Division 11/4 --> 2 drops remainder 11%4 --> 3 % gives remainder Want to find the area of a triangle with height 4 and base 3. 1/2bh How would I write that in C?

14 Displaying Numeric Values Control string tells printf what form to display the result in.  %d – int displayed as decimal  %c – Display char  %f – Display floating point number as decimal number ch2/formats.c

15 What is the output of these two lines? printf("Half off is $%d", 11/2); printf("Tax is $%f\n", 11/2*.06);

16 Next Variables and Assignment Statements.


Download ppt "Basic C Programming Data Types and Arithmetic Operations 01/30/15."

Similar presentations


Ads by Google