More about Numerical Computation

Slides:



Advertisements
Similar presentations
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Advertisements

Lecture 071 CS 192 Lecture 7 Winter 2003 December 15-16, 2003 Dr. Shafay Shamail.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
Loose endsCS-2301, B-Term “Loose Ends” CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations System-oriented Programming, B. Hirsbrunner,
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
Expressions, Data Conversion, and Input
OperatorstMyn1 Operators The sequence in which different operators in an expression are executed is determined by the precedence of the operators. Operators.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 2 part #4 Operator
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
Bit Fields & Bitwise Operations CS-2303, C-Term Bit Fields & Bitwise Operations CS-2303 System Programming Concepts (Slides include materials from.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Expressions and Operators in C. Expressions and Operators Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); Two types: – Function calls – The expressions.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
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.
Free Ebooks Download Mba Ebooks By Edhole Mba ebooks Free ebooks download
Expression and Operator. Expressions and Operators u Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); u Two types: –Function calls –The expressions formed.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2012 CMPE-013/L Operators Gabriel Hugh Elkaim Spring 2012.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Operator Kinds of Operator Precedence of Operator Type Casting.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
CompSci 230 S Programming Techniques
CSE 220 – C Programming Expressions.
Chapter 7: Expressions and Assignment Statements
Lecture 3 Java Operators.
Chap. 2. Types, Operators, and Expressions
Tokens in C Keywords Identifiers Constants
Assignment and Arithmetic expressions
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Conversions of the type of the value of an expression
Arithmetic operations, decisions and looping
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
All the Operators 22-Nov-18.
All the Operators 4-Dec-18.
Chapter-3 Operators.
Lectures on Numerical Methods
Bit Fields & Bitwise Operations
Programming Assignment #5
Differences between Java and C
Homework Homework Continue Reading K&R Chapter 2 Questions?
Expressions.
Chapter 3 Operators and Expressions
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Homework Finishing Chapter 2 of K&R. We will go through Chapter 3 very quickly. Not a lot is new. Questions?
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
OPERATORS in C Programming
Operator King Saud University
OPERATORS in C Programming
Presentation transcript:

More about Numerical Computation Assumptions: Graduate level Operating Systems Making Choices about operation systems Why a micro-century? …just about enough time for one concept CIS 1057 Computer Programming C Fall 2013 (Acknowledgement: Many slides based on/borrowed from Professor Hugh C. Lauer. Slides include materials from The C Programming Language, 2nd edition, by Kernighan and Ritchie and from C: How to Program, 5th and 6th editions, by Deitel and Deitel) CIS 1057 Fall 2013 More about Numerical Computation in C

More Numerical Operators Relational operators <, <=, >, >=, ==, != Return 0 if false, 1 if true Let int a = 3; Then a < 3 returns 0 a >= 3 returns 1 a == 3 returns 1 a != 3 returns 0 CIS 1057 Fall 2013 More about Numerical Computation in C

More Numerical Operators Relational operators are not special in C. They are just like any other operators in expressions Relational operators <, <=, >, >=, ==, != Return 0 if false, 1 if true Let int a = 3; Then a < 3 returns 0 a >= 3 returns 1 a == 3 returns 1 a != 3 returns 0 CIS 1057 Fall 2013 More about Numerical Computation in C

Precedence of Relational Operators Comparisons: lower than arithmetic operators Equality-inequality: lower than comparisons See Table 2-1, p.53 Examples i < lim - 1 means i < (lim – 1) X + (y >= 3) returns the value X (when y < 3) and the value X+1 (when y >= 3) CIS 1057 Fall 2013 More about Numerical Computation in C

Increment & Decrement Operators ++x, --x, x++, x-- Increments or decrements x by 1 ++x – increments x, returns new value of x x++ – increments x, returns old value of x Used in many situations, especially for loops --x – decrements x, returns new value of x x-- – decrements x, returns old value of x High precedence than *, /, % Associates right to left CIS 1057 Fall 2013 More about Numerical Computation in C

More about Numerical Computation in C Bitwise Operations & – bitwise AND | – bitwise OR (inclusive) ^ – bitwise exclusive OR << – left shift Same as multiplying by 2 (i.e., fills low-order bits with zeros) >> – right shift Machine dependent fill on left, depends upon sign bit ~ – one’s complement May only be applied to integral types i.e., int, short, long, char signed or unsigned CIS 1057 Fall 2013 More about Numerical Computation in C

Conditional Expressions expr1 ? expr2 : expr3 Evaluate expr1. If result is true, evaluate and return expr2 Otherwise evaluate and return expr3 Example, z = (a < b) ? a : b Assigns z the value of a if a < b, or b otherwise See tricky code at end of §2.11 For use in Programming Assignment #2 CIS 1057 Fall 2013 More about Numerical Computation in C

Assignment Operator (yet again) location += expression means Add expression to the value at location and assign the result back into the same location Similarly for -=, *=, /=, %=, ^=. |=, <<=, >>= E.g., x *= a is the same as x = x * a y /= b is the same as y = y * b z <<= 3 is the same as z = z << 3 Exceptions will become apparent later in the course CIS 1057 Fall 2013 More about Numerical Computation in C

More about Numerical Computation in C Type Conversion May be automatic or explicit Automatic, for signed operands:– If either is long double, convert other to long double Else if either is double, convert other to double Else if either is float, convert other to float Otherwise, convert char and short to int and then if either is long, convert other to long I.e., “promote” numerical types from lower to higher CIS 1057 Fall 2013 More about Numerical Computation in C

Type Conversion (continued) Automatic type conversion of unsigned integer values is Tricky and Machine dependent CIS 1057 Fall 2013 More about Numerical Computation in C

Explicit Type Conversion Definition – cast A unary operator applied to an expression to explicitly force the value to a particular type Represented as (type) expression High precedence, equal to unary operators Associates right-to-left Example (int) sqrt(2*pi) Converts the square root of 2π to an integer and truncates the fractional part (i.e., no rounding) CIS 1057 Fall 2013 More about Numerical Computation in C

More about Numerical Computation in C Questions? Read or review Chapter 2 CIS 1057 Fall 2013 More about Numerical Computation in C