1 C Fundamentals - I Math 130 Lecture # 2 B Smith: Sp05: With discussion on labs, this took 53 minutes. Score 3. Many caveats. B Smith: Sp05: With discussion.

Slides:



Advertisements
Similar presentations
Thinking Mathematically
Advertisements

Types and Arithmetic Operators
Math 191: Mathematics and Geometry for Designers Lecture Notes Based on The Book Mathematics in Our World by Allan G. Bluman.
1 CSE1301 Computer Programming Lecture 5 C Primitives 2.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Computer Science 1620 Arithmetic. C++ Math we have seen how to use numbers in our program to represent data however, we can also manipulate this data.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Overview Order of presentation different than published handouts Run a program on ccc Finish Arithmetic operations Data types integer char floating point.
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
Data types and variables
ICS 103 Lab 2-Arithmetic Expressions. Lab Objectives Learn different arithmetic operators Learn different arithmetic operators Learn how to use arithmetic.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1)
Chapter 2 Data Types, Declarations, and Displays
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Computer Science 210 Computer Organization Floating Point Representation.
Objectives You should be able to describe: Data Types
Simple Data Type Representation and conversion of numbers
Chapter P Prerequisites: Fundamental Concepts of Algebra
Variables and Exponents
Slide 7- 1 Copyright © 2012 Pearson Education, Inc.
Numeric Types, Expressions, and Output ROBERT REAVES.
CSE1301 Computer Programming Lecture 5: C Primitives 2 Corrections.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
Exponents & Scientific Notation MATH 102 Contemporary Math S. Rook.
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
Section 4.1 The Product, Quotient, and Power Rules for Exponents.
CSC 221 Computer Organization and Assembly Language
CSC 107 – Programming For Science. The Week’s Goal.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Lesson 6 Getting Started in C Programming Hu Junfeng 2007/10/10.
Lesson Two: Everything You Need to Know
Exponents and Scientific Notation MATH 017 Intermediate Algebra S. Rook.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Copyright © – Curt Hill Types What they do.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Variables Symbol representing a place to store information
Doing math In java.
Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
AOIT Introduction to Programming Unit 2, Lesson 6 Arithmetic Operators and Operator Precedence Copyright © 2009–2012 National Academy Foundation. All rights.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Chapter P Prerequisites: Fundamental Concepts of Algebra Copyright © 2014, 2010, 2007 Pearson Education, Inc. 1 P.2 Exponents and Scientific Notation.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
From Algorithms to Programs Both are sets of instructions on how to do a task Algorithm: –talking to humans, easy to understand –in plain (English) language.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
BASIC ELEMENTS OF A COMPUTER PROGRAM
INSPIRING CREATIVE AND INNOVATIVE MINDS
ITEC113 Algorithms and Programming Techniques
Arithmetic Operator Operation Example + addition x + y
Arithmetic Expressions in C
CSI 121 Structured Programming Language Lecture 5: C Primitives 2
Introduction to Java, and DrJava part 1
Chapter 2 Variables.
Introduction to Java, and DrJava
Chapter 3 Operators and Expressions
Data Types and Expressions
Arithmetic Operations
EECE.2160 ECE Application Programming
Introduction to Java, and DrJava
Introduction to Java, and DrJava part 1
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

1 C Fundamentals - I Math 130 Lecture # 2 B Smith: Sp05: With discussion on labs, this took 53 minutes. Score 3. Many caveats. B Smith: Sp05: With discussion on labs, this took 53 minutes. Score 3. Many caveats. B Smith: Fa05: Timing about right B Smith: Fa05: Timing about right B Smith: Sp06: Used Dev-C for most things here and had students do the hands-on experimentation stuff. Rate: 3. Good, practical, programming. B Smith: Sp06: Used Dev-C for most things here and had students do the hands-on experimentation stuff. Rate: 3. Good, practical, programming.

2 Administrivia Lab 1 should be submitted by end of lab today See Blackboard for next few labs  Lab 2 due Friday, Sept 2  Lab 3 due Friday, Sept 9

3 Overview Define basic data type Evaluate Arithmetic Expressions using C

4 Basic data types in C Integer: 2, -50, +2, -2 Floating point: 0.331, , 1.0, +1. Double precision: 6 – 7 digits precision Character: ‘W’, ‘w’, ‘+’, ‘&’ Exponential Notation 5.123e-7

5 Integers (2, -50, +2, -2, etc.) A positive or negative number  with no fractional part or (no decimal point.) From the American Heritage dictionary:  A member of the set of positive whole numbers {1, 2, 3,... }, negative whole numbers {-1, -2, -3,... }, and zero {0} Can be “signed” or “unsigned” 5622 ok, but not ?  There is a limit to the size of allowed integer types B Smith: Show table (list) as an example: If we have only 6 spots available, you can have signed: -3,-2,-1,0,1,2 or unsigned: 0,1,2,4,5,6 B Smith: Show table (list) as an example: If we have only 6 spots available, you can have signed: -3,-2,-1,0,1,2 or unsigned: 0,1,2,4,5,6 B Smith: not covered Fa 05 B Smith: not covered Fa 05

6 Arithmetic Expressions take arithmetic (numerical) values and return an arithmetic (numerical) value Are composed using the following operators: + (unary plus) - (unary minus) + (addition) - (subtraction) * (multiplication) / (division or quotient) % (modulus or remainder) L01a.c B Smith: This is a great opportunity to start using a debugger in class to show variable changes. This would be an alternative to using printf to trace through a program! B Smith: This is a great opportunity to start using a debugger in class to show variable changes. This would be an alternative to using printf to trace through a program!

7 Unary operators Called unary because they require one operand. Examples i = +1;/* + used as a unary operator */ j = -i;/* - used as a unary operator */ The unary operator ‘+’ does nothing  just emphasis that a numeric constant is positive. The unary operator ‘–’ produces the negative of its operand.

8 Precedence in Expressions Defines the order in which an expression is evaluated As in algebra we need rules regarding what gets done first Write down your answers to the following:

9 Precedence in Expressions * / 5 = P stands for parentheses, E for Exponents, M for multiplication D for division, A for addition, and S for subtraction. P.E.M.D.A.S. 1 + (2 * 3) - (4 / 5)

10 More on precedence *, /, % are at the same level of precedence +, - are at the same level of precedence For operators at the same “level,” left-to-right ordering is applied – 1 = (2 + 3) – 1 = 4 2 – = (2 – 3) + 1 = 0 2 * 3 / 4 = (2 * 3) / 4 = 6 / 4 2 / 3 * 4 = (2 / 3) * 4 = 0 / 4 B Smith: Provide an example for next slide. Your turn... B Smith: Provide an example for next slide. Your turn...

11 Precedence in Expressions – Example (cont) * / 5 = 1 + (2 * 3) - (4 / 5) B Smith: This entire sequence can be covered on 1 slide using a tablet B Smith: This entire sequence can be covered on 1 slide using a tablet

12 Precedence in Expressions – Example (cont) * / 5 = 1 + (2 * 3) - (4 / 5)

13 Precedence in Expressions – Example (cont) Integer division results in integer quotient * / 5 = 1 + (2 * 3) - (4 / 5)

14 Precedence in Expressions – Example (cont) = * / 5 = 1 + (2 * 3) - (4 / 5)

15 Precedence in Expressions – Example (cont) * / 5 = 1 + (2 * 3) - (4 / 5)

16 int -s and float -s float is a “communicable” type Example: * / 5 = 1 + (2 * 3) - (4.0 / 5) = = 6.2 B Smith: Redundant since done on board with tablet. Consider writing out line 1 and finishing live B Smith: Redundant since done on board with tablet. Consider writing out line 1 and finishing live

17 int -s and float -s – Example 2 (1 + 2) * (3 - 4) / 5 = ((1 + 2) * (3 - 4)) / 5 = (3 * -1) / 5 = -3 / 5 = 0

18 int -s and float -s – Example 2 (cont) ( ) * (3 - 4) / 5 = (( ) * (3 - 4)) / 5 = (3.0 * -1) / 5 = -3.0 / 5 = -0.6

19 int -s and float -s – Example 3 ( ) * ((3 - 4) / 5) = ( ) * (-1 / 5) = 3.0 * 0 = 0.0

20 Floating Point and Exponential Notation (e.g e4, 3.1e-3, 7e0) Generally written in exponential format  i.e., 3000 would be 3e3 and  1/1000 or would be 1e-3 the precision of the floating-point representation is determined by the number of digits the computer will allow for the decimal part of the mantissa  i.e. in 2.555e4, is the mantissa Whereas the the range of the floating-point representation is based on the number of digits the computer allows for the exponent  i.e., in 2.555e4, 4 is the exponent

21 Summary Defined basic data type Evaluated Arithmetic Expressions using C Read chapter 2 of your book and review lectures notes