# Variables and constants linked with operators. Uses relational and logical operators Evaluates to 1 or 0 (true or false) only

Save this PDF as:

Size: px
Start display at page:

Download "Variables and constants linked with operators. Uses relational and logical operators Evaluates to 1 or 0 (true or false) only"

## Transcription

1 Expressions 1

2 Expressions Variables and constants linked with operators Arithmetic expressions Uses arithmetic operators Can evaluate to any value Logical expressions Uses relational and logical operators Evaluates to 1 or 0 (true or false) only Assignment expression Uses assignment operators Evaluates to value depending on assignment 2

3 Arithmetic Operators Binary operators Addition: + Subtraction: Division: / Multiplication: * Modulus: % Unary operators Plus: + Minus: Examples 2* / *25/5 7 distance / time 3.14* radius * radius a * x * x + b*x + c dividend / divisor 37 % 10 3

4 Contd. Suppose x and y are two integer variables, whose values are 13 and 5 respectively x + y 18 x y 8 x * y 65 x / y 2 x % y 3 4

5 All operators except % can be used with operands of all of the data types int, float, double, char (yes! char also! We will see what it means later) % can be used only with integer operands 5

6 Operator Precedence In decreasing order of priority 1. Parentheses :: ( ) 2. Unary minus :: 5 3. Multiplication, Division, and Modulus 4. Addition and Subtraction For operators of the same priority, evaluation is from left to right as they appear Parenthesis may be used to change the precedence of operator evaluation 6

7 Examples: Arithmetic expressions a + b * c d / e a + (b * c) (d / e) a * b + d % e f a * ( b) + (d % e) f a b + c + d (((a b) + c) + d) x * y * z ((x * y) * z) a + b + c * d * e (a + b) + ((c * d) * e) 7

8 Type of Value of an Arithmetic Expression If all operands of an operator are integer (int variables or integer constants), the value is always integer Example: 9/5 will be 1, not 1.8 Example: int a=9, b=5; printf( %d, a/b) will print 1 and not 1.8 8

9 If at least one operand is real, the value is real Caution: Since floating-point values are rounded to the number of significant digits permissible, the final value is an approximation of the final result Example: 1/ 3.0 * 3.0 may have the value and not 1.0 So checking if 1/ 3.0 * 3.0 is equal to 1.0 may return false!! 9

10 The type of the final value of the expression can be found by applying these rules again and again as the expression is evaluated following operator precedence 10

11 We have a problem!! int a=10, b=4, c; float x; c = a / b; x = a / b; The value of c will be 2 The value of x will be 2.0 But we want 2.5 to be stored in x We will take care of this a little later 11

12 Assignment Expression Uses the assignment operator (=) General syntax: variable_name = expression Left of = is called l-value, must be a modifiable variable Right of = is called r-value, can be any expression Examples: velocity = 20 b = 15; temp = 12.5 A = A + 10 v = u + f * t s = u * t * f * t * t 12

13 Contd. An assignment expression evaluates to a value same as any other expression Value of an assignment expression is the value assigned to the l-value Example: value of a = 3 is 3 b = 2*4 6 is 2 n = 2*u + 3*v w is whatever the arithmetic expression 2*u + 3*v w evaluates to given the current values stored in variables u, v, w 13

14 Contd. Several variables can be assigned the same value using multiple assignment operators a = b = c = 5; flag1 = flag2 = y ; speed = flow = 0.0; Easy to understand if you remember that the assignment expression has a value Multiple assignment operators are right-to-left associative 14

15 Example Consider a= b = c = 5 Three assignment operators Rightmost assignment expression is c=5, evaluates to value 5 Now you have a = b = 5 Rightmost assignment expression is b=5, evaluates to value 5 Now you have a = 5 Evaluates to value 5 So all three variables store 5, the final value the assignment expression evaluates to is 5 15

16 Types of l-value and r-value Usually should be the same If not, the type of the r-value will be internally converted to the type of the l-value, and then assigned to it Example: double a; a = 2*3; Type of r-value is int and the value is 6 Type of l-value is double, so stores

17 This can cause strange problems int a; a = 2*3.2; Type of r-value is float/double and the value is 6.4 Type of l-value is int, so internally converted to 6 So a stores 6, not the correct result But an int cannot store fractional part anyway So just badly written program Be careful about the types on both sides 17

18 More Assignment Operators +=, -=, *=, /=, %= Operators for special type of assignments a += b is the same as a = a + b Same for -=, *=, /=, and %= Exact same rules apply for multiple assignment operators 18

19 Contd. Suppose x and y are two integer variables, whose values are 5 and 10 respectively. x += y x = y x *= y x /= y Stores 15 in x Evaluates to 15 Stores -5 in x Evaluates to -5 Stores 50 in x Evaluates to 50 Stores 0 in x Evaluates to 0 19

20 Logical Expressions Uses relational and logical operators in addition Informally, specifies a condition which can be true or false Evaluates to value 0 or 1 0 implies the condition is false 1 implies the condition is true 20

21 Logical Expressions (count <= 100) ((math+phys+chem)/3 >= 60) ((sex == M ) && (age >= 21)) ((marks >== 80) && (marks < 90)) ((balance > 5000) (no_of_trans > 25)) (! (grade == A )) 21

22 Relational Operators Used to compare two quantities. < is less than > is greater than <= is less than or equal to >= is greater than or equal to == is equal to!= is not equal to 22

23 Examples 10 > 20 is false, so value is 0 25 < 35.5 is true, so value is 1 12 > (7 + 5) is false, so value is 0 32!= 21 is true, so value is 1 When arithmetic expressions are used on either side of a relational operator, the arithmetic expressions will be evaluated first and then the results compared a + b > c d is the same as (a+b) > (c+d) 23

24 Logical Operators Logical AND (&&) Evalutes to 1 if both the operands are non-zero Logical OR ( ) Result is true if at least one of the operands is non-zero X Y X && Y X Y non-0 0 non-0 non non-0 non-0 non-0 non-0 non-0 24

25 Contd Unary negation operator (!) Single operand Value is 0 if operand is non-zero Value is 1 if operand is 0 25

26 Example (4 > 3) && (100!= 200) 4 > 3 is true, so value 1 100!= 200 is true so value 1 Both operands 1 for &&, so final value 1 (!10) && ( != 200) 10 is non-0, so value!10 is != 200 is true so value 1 Both operands NOT 1 for &&, so final value 0 (!10) ( != 200) Same as above, but at least one value non-0, so final value 1 26

27 a = 3 && b = 4 No parenthesis, so need to look at precedence and associativity = has higher precedence than && b=4 is an assignment expression, evaluates to 4 a = 3 is an assignment expression, evaluates to 3 Both operands of && are non-0, so final value of the logical expression is 1 Note that changing to b = 0 would have made the final value 0 27

28 Example: Use of Logical Expressions void main () { int i, j; scanf( %d%d,&i,&j); printf ( %d AND %d = %d, %d OR %d=%d\n, i,j,i&&j, i,j, i j) ; } If 3 and 0 are entered from keyboard, output will be 3 AND 0 = 0, 3 OR 0 = 1 28

29 A Special Operator: AddressOf (&) Remember that each variable is stored at a location with an unique address Putting & before a variable name gives the address of the variable (where it is stored, not the value) Can be put before any variable (with no blank in between) int a =10; printf( Value of a is %d, and address of a is %d\n, a, &a); 29

30 More on Arithmetic Expressions 30

31 Recall the earlier problem int a=10, b=4, c; float x; c = a / b; x = a / b; The value of c will be 2 The value of x will be 2.0 But we want 2.5 to be stored in x 31

32 Solution: Typecasting Changing the type of a variable during its use General form (type_name) variable_name Example x = ((float) a)/ b; Now x will store 2.5 (type of a is considered to be float for this operation only, now it is a mixedmode expression, so real values are generated) 32

33 Not everything can be typecast to anything float/double should not be typecast to int (as an int cannot store everything a float/double can store) int should not be typecast to char (same reason) General rule: make sure the final type can store any value of the initial type 33

34 Example: Finding Average of 2 Integers Wrong program int a, b; float avg; scanf( %d%d, &a, &b); avg = (a + b)/2; printf( %f\n, avg); average-1.c int a, b; float avg; scanf( %d%d, &a, &b); avg = ((float) (a + b))/2; printf( %f\n, avg); Correct programs int a, b; float avg; scanf( %d%d, &a, &b); avg = (a + b)/2.0; printf( %f\n, avg); average-2.c 34

35 More Operators: Increment (++) and Decrement (--) Both of these are unary operators; they operate on a single operand The increment operator causes its operand to be increased by 1 Example: a++, ++count The decrement operator causes its operand to be decreased by 1. Example: i--, --distance 35

36 Pre-increment versus postincrement Operator written before the operand (++i, --i)) Called pre-increment operator (also sometimes called prefix ++ and prefix --) Operand will be altered in value before it is utilized in the program Operator written after the operand (i++, i--) Called post-increment operator (also sometimes called postfix ++ and postfix --) Operand will be altered in value after it is utilized in the program 36

37 Examples Initial values :: a = 10; b = 20; x = a; a = 11, x = 61 x = 50 + a++; x = 60, a = 11 x = a b; b = 19, x = 29, a = 11 x = a++ ++a;?? Called side effects (while calculating some values, something else gets changed) 37

38 Precedence among different operators (there are many other operators in C, some of which we will see later) Operator Class Operators Associativity Unary postfix++, -- Left to Right Unary prefix ++, --! & Right to Left Binary * / % Left to Right Binary + Left to Right Binary < <= > >= Left to Right Binary ==!= Left to Right Binary && Left to Right Binary Left to Right Assignment = += = *= /= &= Right to Left 38

39 Statements in a C program Parts of C program that tell the computer what to do Different types Declaration statements Declares variables etc. Assignment statement Assignment expression, followed by a ; Control statements For branching and looping, like if-else, for, while, dowhile (to be seen later) Input/Output Read/print, like printf/scanf 39

40 Example Declaration statement int a, b, larger; scanf( %d %d, &a, &b); larger = b; Control if (a > b) statement larger = a; printf( Larger number is %d\n, larger); Assignment statement Input/Output statement 40

41 Compound statements A sequence of statements enclosed within { and } Each statement can be an assignment statement, control statement, input/output statement, or another compound statement We will also call it block of statements sometimes informally 41

42 Example int n; scanf( %d, &n); while(1) { if (n > 0) break; scanf( %d, &n); } Compound statement 42

### Chapter 4 Operators & Arithmetic

Chapter 4 Operators & Arithmetic 4-1 Arithmetic in C++ Arithmetic expressions can be made up of constants, variables, operators and parentheses. The arithmetic operators in C++ are as follows + (addition)

### Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

### Chapter 2: Elements of Java

Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

### Introduction to Programming

Introduction to Programming SS 2012 Adrian Kacso, Univ. Siegen adriana.dkacsoa@duni-siegena.de Tel.: 0271/740-3966, Office: H-B 8406 Stand: April 25, 2012 Betriebssysteme / verteilte Systeme Introduction

### Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

### arrays C Programming Language - Arrays

arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)

### Borland C++ Compiler: Operators

Introduction Borland C++ Compiler: Operators An operator is a symbol that specifies which operation to perform in a statement or expression. An operand is one of the inputs of an operator. For example,

### Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero THEN the Average is Sum divided by Count Conditions

### C Programming Dr. Hasan Demirel

C How to Program, H. M. Deitel and P. J. Deitel, Prentice Hall, 5 th edition (3 rd edition or above is also OK). Introduction to C Programming Dr. Hasan Demirel Programming Languages There are three types

### Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

### Primitive Data Types Summer 2010 Margaret Reid-Miller

Primitive Data Types 15-110 Summer 2010 Margaret Reid-Miller Data Types Data stored in memory is a string of bits (0 or 1). What does 1000010 mean? 66? 'B'? 9.2E-44? How the computer interprets the string

### Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++

Adjusted/Modified by Nicole Tobias Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types

### Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

### Java How to Program, 9/e

Java How to Program, 9/e Education, Inc. All Rights Reserved. 1 Any computing problem can be solved by executing a series of actions in a specific order. An algorithm is a procedure for solving a problem

### C Syntax and Semantics

C Syntax and Semantics 1 C Program Structure C Language Elements Preprocessor directives Function Header, and Function body Executable statements Reserved word, Standard identifiers, user defined identifiers

### Sources: On the Web: Slides will be available on:

C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

### Birla Institute of Technology &Science, Pilani Computer Programming (CS F111) Second Semester Lab-3 (Introduction to C Programming Language)

Topics to be covered: 1. C Program structure and execution 2. Data type 3. Reading input and printing output 4. Expression 5. Operator precedency 6. Typecasting Birla Institute of Technology &Science,

### Lecture 2 Notes: Flow of Control

6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

### Fundamentals of Programming

Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

### JavaScript: Control Statements I

1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

### PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :

### C++ Language Tutorial

cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

### Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

### Object Oriented Software Design

Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

### Statements and Control Flow

Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

### Object Oriented Software Design

Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

### Lecture 1 Introduction to Java

Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First

### Example of a Java program

Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

### CMSC 106 Introduction to C Programming

CMSC 106 Introduction to C Programming Math Library, Escape Sequences, Conditionals CMSC 106 - Slides developed by Jan Plane with some modifications by Nelson Padua-Perez Additional Operators Increment

### TI-83 Plus Graphing Calculator Keystroke Guide

TI-83 Plus Graphing Calculator Keystroke Guide In your textbook you will notice that on some pages a key-shaped icon appears next to a brief description of a feature on your graphing calculator. In this

1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

### Chapter One Introduction to Programming

Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

### Computer Programming. Loops(2) do-while, for

Computer Programming Loops(2) do-while, for Topics Repeating Statements (review) while loop (review) do-while loop for loop Infinite loops Examples Repeating Statements In many cases same operations are

### Computers process data under the control of sets of instructions called computer programs.

Introduction Computer is a device capable of performing computations and making logical decisions at speeds millions and even billions of times faster than human beings. Computers process data under the

### Objective-C Tutorial

Objective-C Tutorial OBJECTIVE-C TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Objective-c tutorial Objective-C is a general-purpose, object-oriented programming

### ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

ECE 0142 Computer Organization Lecture 3 Floating Point Representations 1 Floating-point arithmetic We often incur floating-point programming. Floating point greatly simplifies working with large (e.g.,

### INTRODUCTION TO FLOWCHARTING

CHAPTER 1 INTRODUCTION TO FLOWCHARTING 1.0 Objectives 1.1 Introduction 1.2 Flowcharts 1.3 Types of Flowcharts 1.3.1 Types of flowchart 1.3.2 System flowcharts 1.4 Flowchart Symbols 1.5 Advantages of Flowcharts

### Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

### Order of Operations. 2 1 r + 1 s. average speed = where r is the average speed from A to B and s is the average speed from B to A.

Order of Operations Section 1: Introduction You know from previous courses that if two quantities are added, it does not make a difference which quantity is added to which. For example, 5 + 6 = 6 + 5.

### Order of Operations - PEMDAS. Rules for Multiplying or Dividing Positive/Negative Numbers

Order of Operations - PEMDAS *When evaluating an expression, follow this order to complete the simplification: Parenthesis ( ) EX. (5-2)+3=6 (5 minus 2 must be done before adding 3 because it is in parenthesis.)

### The C Programming Language course syllabus associate level

TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

### Python to C/C++ Fall 2011

Python to C/C++ Fall 2011 1. Main Program Python: Program code is indented after colon : def main(): body of program C/C++: Have more setup overhead. C: Both require #include directives to access libraries

About The Tutorial C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.

### Arrays. Arrays, Argument Passing, Promotion, Demotion

Arrays Arrays, Argument Passing, Promotion, Demotion Review Introduction to C C History Compiling C Identifiers Variables Declaration, Definition, Initialization Variable Types Logical Operators Control

### Introduction to Problem Solving Techniques

UNIT 1 Introduction to Problem Solving Techniques Structure 1.0 Introduction 1.1 Procedure (steps involved in problem solving) 1.2 Algorithm 1.3 Flow Chart 1.4 Symbols used in Flow Charts 1.5 Pseudo Code

### 1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C

Character set in C We should use only the following characters in writing a C program. These characters can be combined to create C words. Alphabet: A, B, C, D.. Z, a, b, c, d..z Numeric digits: 0, 1,

### In this Chapter you ll learn:

Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

### PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

### Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

### CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

### The Basics of C Programming. Marshall Brain

The Basics of C Programming Marshall Brain Last updated: October 30, 2013 Contents 1 C programming 1 What is C?................................. 2 The simplest C program, I........................ 2 Spacing

### 9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

### Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Divide: Paper & Pencil Computer Architecture ALU Design : Division and Floating Point 1001 Quotient Divisor 1000 1001010 Dividend 1000 10 101 1010 1000 10 (or Modulo result) See how big a number can be

### COMPUTER SKILLS LESSON 3

COMPUTER SKILLS LESSON 3 Prof. Valeria Cardellini cardellini@ing.uniroma2.it Prof. Emiliano Casalicchio casalicchio@ing.uniroma2.it Computer Skills - Lesson 3 - V. Cardellini 2 The professors Valeria Cardellini,

### Key concepts. C++ character set. Tokens. Keywords Identifiers Literals Punctuators Operators. Integrated Development Environment (IDE)

5 1 Key concepts C++ character set Tokens o o o o o Keywords Identifiers Literals Punctuators Operators Integrated Development Environment (IDE) o o Turbo C++ IDE Geany IDE C++ (pronounced "C plus plus")

### 3 First Steps in C Programming

3 First Steps in C Programming The following is the typical structure of an executable C program: / C Program Structure / / This is a multline comment / / These are pre processor directives to include

### So far we have considered only numeric processing, i.e. processing of numeric data represented

Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate

### TI-86 Graphing Calculator Keystroke Guide

TI-86 Graphing Calculator Keystroke Guide In your textbook you will notice that on some pages a key-shaped icon appears next to a brief description of a feature on your graphing calculator. In this guide

### Introduction to Python

Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment

### This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

This Unit: Floating Point Arithmetic CIS 371 Computer Organization and Design Unit 7: Floating Point App App App System software Mem CPU I/O Formats Precision and range IEEE 754 standard Operations Addition

### Chapter 8 Selection 8-1

Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

### Selection Statements

Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:

http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

### 1 Description of The Simpletron

Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

### COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

### Computer Programming Tutorial

Computer Programming Tutorial COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Computer Prgramming Tutorial Computer programming is the act of writing computer

### Chapter 3 Operators and Control Flow

Chapter 3 Operators and Control Flow I n this chapter, you will learn about operators, control flow statements, and the C# preprocessor. Operators provide syntax for performing different calculations or

### Introduction to Java

Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

### PL / SQL Basics. Chapter 3

PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

### QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1

QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For

### The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical

### Programming and Data Structures

Programming and Data Structures Tutorial sheet: 2 Topics: Decision Making, Looping and Branching Q 1. (a) What is wrong with the following loop while ( n

### DNA Data and Program Representation. Alexandre David 1.2.05 adavid@cs.aau.dk

DNA Data and Program Representation Alexandre David 1.2.05 adavid@cs.aau.dk Introduction Very important to understand how data is represented. operations limits precision Digital logic built on 2-valued

### C programming: exercise sheet L2-STUE (2011-2012)

C programming: exercise sheet L2-STUE (2011-2012) Algorithms and Flowcharts Exercise 1: comparison Write the flowchart and associated algorithm that compare two numbers a and b. Exercise 2: 2 nd order

### C Reference Manual. Dennis M. Ritchie Bell Telephone Laboratories Murray Hill, New Jersey 07974

C Reference Manual Dennis M. Ritchie Bell Telephone Laboratories Murray Hill, New Jersey 07974 1. Introduction C is a computer language based on the earlier language B [1]. The languages and their compilers

### Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

### ALGORITHMS AND FLOWCHARTS

ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps

### Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

### Tutorial on C Language Programming

Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

### 3/13/2012. ESc101: Multiple statement execution using loops. Loops are used when instructions are repeated. while statement can be used for a loop

ESc101: Multiple statement execution using loops Instructor: Krithika Venkataramani Semester 2, 2011-2012 The content of most of these slides are taken from the lecture slides of Prof. Arnab Bhattacharya

### C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu

C / C++ and Unix Programming Materials adapted from Dan Hood and Dianna Xu 1 C and Unix Programming Today s goals ú History of C ú Basic types ú printf ú Arithmetic operations, types and casting ú Intro

### Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Chapter 3 Control Structures 1 Control structures Algorithm Development Conditional Expressions Selection Statements Repetition Statements Structuring

### Introduction to C++ Programming

2 Introduction to C++ Programming OBJECTIVES In this chapter you will learn: To write simple computer programs in C++. To write simple input and output statements. To use fundamental types. Basic computer

### 4 Operations On Data

4 Operations On Data 4.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, students should be able to: List the three categories of operations performed on

### Common Syntax and Semantic Errors

C H A P T E R 2 Common Syntax and Semantic Errors 2.1 CHAPTER OBJECTIVES To understand the fundamental characteristics of syntax and semantic errors To be able to identify specific common syntax and semantic

### Chapter 5. Selection 5-1

Chapter 5 Selection 5-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

### We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

### can have one of only two possible values true (displayed as 1) and false (displayed as 0) special functions: true and false y = false y =

Logical Data Type A special type of data that can have one of only two possible values true (displayed as ) and false (displayed as ) These values are produced by special functions: true and false x =

### Basic Formulas in Excel. Why use cell names in formulas instead of actual numbers?

Understanding formulas Basic Formulas in Excel Formulas are placed into cells whenever you want Excel to add, subtract, multiply, divide or do other mathematical calculations. The formula should be placed

### Java Interview Questions and Answers

1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

### 5 Arrays and Pointers

5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of

### Conditions & Boolean Expressions

Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In

### LECTURE NOTE on PROGRAMMING IN C

LECTURE NOTE on PROGRAMMING IN C COURSE CODE: MCA 101 By Asst. Professor Mrs Etuari Oram Asst. Prof. Mr Bighnaraj Naik SYLLABUS Module I C Language Fundamentals. Character set, Identifiers, keyword, data

### Writing Control Structures

Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify

### Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

### Chapter 3: Writing C# Expressions

Page 1 of 19 Chapter 3: Writing C# Expressions In This Chapter Unary Operators Binary Operators The Ternary Operator Other Operators Enumeration Expressions Array Expressions Statements Blocks Labels Declarations