Arithmetic Instructions. Integer and Float Conversions.

Slides:



Advertisements
Similar presentations
© 2007 Lawrenceville Press Slide 1 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5;
Advertisements

C Language Elements (II) H&K Chapter 2 Instructor – Gokcen Cilingir Cpt S 121 (June 22, 2011) Washington State University.
True or false A variable of type char can hold the value 301. ( F )
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++ (4) 10 September.
Introduction to Computers and Programming - Class 2 1 Introduction to Computers and Programming Class 2 Introduction to C Professor Avi Rosenfeld.
ISBN Chapter 7 Expressions and Assignment Statements.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Expressions, Evaluation and Assignments
A First Book of ANSI C Fourth Edition
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
COMP4730/2002/lec7/H.Melikian Arithmetic Expressions Overloaded Operators Type Conversations Relational and Boolean Expressions Short Circuit Evaluation.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
ISBN Chapter 7 Expressions and Assignment Statements.
1 CSC103: Introduction to Computer and Programming Lecture No 6.
Lesson 1.7 Dividing Integers Standards: NS 1.2 and AF 2.1 Objectives: Dividing Integers Evaluate variable expressions.
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.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C.
Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment.
Chapter 7 Expressions and Assignment Statements. Outline Introduction Arithmetic Expressions Overloaded Operators Type Conversions Assignment Statements.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
LOOP & Type Conversion. do – while Loop In the while loop, the test expression is evaluated at the beginning of the loop. If the test condition is false.
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Type Systems I was eventually persuaded of the need to design programming notations so as.
ISBN Chapter 7 Expressions and Assignment Statements.
1 Program Planning and Design Important stages before actual program is written.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
1 CS161 Introduction to Computer Science Topic #6.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Simplify Radical Expressions Using Properties of Radicals.
Unit 1 Review By: Mr. Jacobs.
Chapter 7 Expressions and Assignment Statements. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 7 Topics Introduction Arithmetic Expressions.
Chapter 7: Expressions and Assignment Statements
Simplify Radical Expressions Using Properties of Radicals
Computing Fundamentals
Chapter 2 Assignment and Interactive Input
Data Types, Identifiers, and Expressions
Chapter 7: Expressions and Assignment Statements
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Arithmetic operations & assignment statement
Arithmetic Operator Operation Example + addition x + y
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Introduction to C++ Programming
A First Book of ANSI C Fourth Edition
College of Computer Science and Engineering
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Chapter-3 Operators.
Lecture3.
Doing Arithmetic Today’s lecture is in chapter 2 Assignment statement:
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Chapter 3 Operators and Expressions
INC 161 , CPE 100 Computer Programming
Chapter 7 Expressions and Assignment Statements.
Chapter 4: Expression and Operator
An Overview of C.
PRESENTED BY ADNAN M. UZAIR NOMAN
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

Arithmetic Instructions

Integer and Float Conversions

Type Conversions in Assignments k is an integer variable a is real

Operator Precedence

Precedence and Associativity When an expression contains two operators of equal priority or precedence the tie between them is settled using the associativity of the operators. Associativity can be of two types— – Left to Right eg. a=3/2*5 – Right to Lefteg. a=b=c

A First Book of ANSI C, 4th edition9 Operator Precedence and Associativity Example: * 7 % 2 * 4 = % 2 * 4 = * 4 = = * 7 % 2 * 4 =

Order of Operations

Assume x=2.0 and y=6.0. Evaluate the statement float z= x+3*x/(y-4);

Writing Algebric Expressions in C

( 3 * ( z + y ) )

Types of Program Errors

Slide 19 Program Errors Syntax errors – Violation of the grammar rules of the language – Discovered by the compiler Error messages may not always show correct location of errors Run-time errors – Error conditions detected by the computer at run-time Logic errors – Errors in the program’s algorithm – Most difficult to diagnose – Computer does not recognize an error

Syntax Error Example #include int main() { char ch, ch1, ch2 /* <<< semicolon removed */ scanf("%c %c %c", &ch, &ch1, &ch2); printf("ch = %c\n", ch); printf("ch1 = %c\n", ch1); printf("ch2 = %c\n", ch2); return 0; }

Logical Error Example #include int main() { /* We want to multiply two numbers! Find where is the error??? */ int a=10, b=2; int result = a/b; /* Logic error! */ printf("result = %d", result); return 0; }

Runtime Error Example #include int main() { int i=10; i = i/0; // Divide by Zero printf("Hello"); return 0; }

Practice Questions