Chapter 4 C Program Control

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Chapter 4 C Program Control"

Transcription

1 Chapter 4 C Program Control

2 Objectives of this chapter: Repetitions will be considered in greater detail for.. repetition do while repetition Also multiple selection switch case statement will be learned. All these are called as program control statements Usage of break and continue statements in the program control statements. break continue Usage of logical operators (AND OR) for combining conditions

3 Repetition Essentials: Most of the programs involves repetitions or looping. The instructions placed in a loop executed repeatedly while the condition of repetition remains true. There are two types of repetitions as mentioned in Chap 3 Counter controlled repetitions Sentinel controlled repetitions

4 Example: Counter-Controlled Repetitions The following program prints out integer numbers from 1 to 10. Page 131 This program can be also written easily using for repetition Notice that the starting value and end value for the counter is known.

5 Page 132 All counter-controlled repetitions can be handled by using for repetitions

6 Example: Rewrite the program that produces the following output using for repetition.*

7 Example - Sum of Even Numbers: for Repetition Write a C program that determines the sum of the even numbers from 2 to 100. * Page 136

8 Chapter 3 Exercise - Page 124 We have already answered this program using counter-controlled repetition with while statement. Let s now rewrite this program using for repetition statement.

9 Switch.. Case Statements: Multiple Selection Statements Page 139 As an alternative to if.. else when dealing with multi-branching in C programming is the switch case controls. This statement also known as multiple choice statements. C-Syntax: switch ( test ) { case 1 : // Process for test = 1... break;. case 5 : // Process for test = 5... break; default : // Process for all other cases.... } Flow-Chart:

10 Example: Using Switch Case Statement Write a C program that reads 10 letter grades for a quiz results. Then writes out the sum of the each letter grades as shown below. The terminal output of the program should look as below when executed. The program s output should look like as follow: Page 140

11 Page 145 Do while is another type of repetition statement used in C. It is similar to while repetition while Repetition: Loop condition is tested at the beginning of the loop do While Repetition: Loop condition is tested at the end of the loop C-Syntax: C-Syntax: while (condition) do { { instructions instructions } } while (condition);

12 Example: Using Do While Repetition Write a C program that prints out the numbers from 1 to 10. The output of the program should be as shown below. * Page 146

13 Page 146 break and continue statements are used to alter the flow of the program. break: Break statement in a switch case used to skip remainder of statement. Break also can be used in repetition statements. The break statement are used to escape early from a repetition/loop. So if break statement used in a repetition it terminates the loop immediately. * Page 147

14 Page 147 break and continue statements are used to alter the flow of the program. continue: the continue usually used in repetition statements to skip the rest of the actions. Unlike break statements terminating the repetition, it only skips the rest of the actions. * Page 147

15 Page 147 So far we have studied programs including simple condition e.g. relation and equality operators (<, >, <=, <=, ==, and!=). C and other programming languages also provides (AND and OR) logical operators to form more complex conditions by combining simple conditions. C-Syntax && : is AND logical operator. : is OR logical operator. Logical operators are written between the simple conditions to be combined Condition1 && Condition2 : two conditions combined with AND Condition1 Condition2 : two conditions combined with OR Example: If ( x > 99 && x <= 999 ) printf( This is a three digit positive integer ); If (x > 0 && y > 0) printf ( This vector is in first quadrant. ); If (gender == 1 && age > 65) seniorfemale++;

16 TRUTH TABLES FOR LOGICAL OPERATORS ( && and ) The outcome of a simple condition in C is 1 for true and 0 for false. Then if or any repetition is executed upon this output value. x==4 gives 1 if true or gives 0 if false. Tables below shows all possible input values of 0 or 1 and output values for && and II operators. These tables are called truth tables. Example: int x=123; if ( x > 0 && x <= 999 ) printf( This is a three digit positive integer ); Question: What happens if we write x==4 in a line rather then x=4? What happens if we write if (x=4) instead of x==4?

17 Page 146

18 Page 162

19 Page 166 Below is the output of the program when executed: Sum of the 5 values is 1500 Or another output of the program when it is executed for only 3 values Sum of the 3 values is 310

20 Below is the output of the program when executed: Enter the number of integers to be processed: 5 Enter an integer: 372 Enter next integer: 920 Enter next integer: 73 Enter next integer: 8 Enter next integer: 3433 The smallest integer is: 8 Page 167

21 Below is the output of the program when executed: Product of the odd integers from 1 to 15 is: Page 167

22 Page 167 Below is the output of the program when executed: N N!

23 Page 169

Engineering Problem Solving with C++, Etter/Ingber

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

More information

switch Multiple-Selection Statement

switch Multiple-Selection Statement switch Multiple-Selection Statement (This feature is rarely useful, although it s perfect for programming the iterative song The Twelve Days of Christmas!) If no match occurs, the default case is executed,

More information

Indicates the end of data when the number of data is not known in advance Must be distinct from the data but be of the same type

Indicates the end of data when the number of data is not known in advance Must be distinct from the data but be of the same type Program Control Essentials of repetition Loop control variable Counts the number of repetitions in the counter-controlled loop Controls the execution of loop Sentinel value Indicates the end of data when

More information

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

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

More information

Repetition and Loops. Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed.

Repetition and Loops. Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed. New Topic Repetition and Loops Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed. These constructs are the 1. while loop and

More information

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

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

More information

Looping Exercises Deciding Which Loop to Use

Looping Exercises Deciding Which Loop to Use Looping Exercises Deciding Which Loop to Use At this time you have learned four looping constructs (also called repetition statements). Each of these four loops are ideal to use in different situations.

More information

cin >> num1 >> num2 >> num3 >> num4 >> num5; sum = num1 + num2 + num3 + num4 + num5; average = sum / 5.

cin >> num1 >> num2 >> num3 >> num4 >> num5; sum = num1 + num2 + num3 + num4 + num5; average = sum / 5. Lesson Outcomes At the end of this chapter, student should be able to: Understand the requirement of a loop Understand the Loop Control Variable (LCV) Use increment (++) and decrement (--) operators Program

More information

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 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

More information

Control Structure. Pseudocode: Input number If number is even Then Print even Else print odd. Flowchart: Begin. End. Print Odd. number even?

Control Structure. Pseudocode: Input number If number is even Then Print even Else print odd. Flowchart: Begin. End. Print Odd. number even? Control Structure Normally, a program is executed in a sequential manner.however, in many cases, a program has to choose among alternative statements C++ provides constructs that enable the programmer

More information

The While Loop. Objectives. Textbook. WHILE Loops

The While Loop. Objectives. Textbook. WHILE Loops Objectives The While Loop 1E3 Topic 6 To recognise when a WHILE loop is needed. To be able to predict what a given WHILE loop will do. To be able to write a correct WHILE loop. To be able to use a WHILE

More information

While and Do-While Loops. 15-110 Summer 2010 Margaret Reid-Miller

While and Do-While Loops. 15-110 Summer 2010 Margaret Reid-Miller While and Do-While Loops 15-110 Margaret Reid-Miller Loops Within a method, we can alter the flow of control using either conditionals or loops. The loop statements while, do-while, and for allow us execute

More information

Pseudocode. Pseudocode. Guide for Pseudocode. Computers in Engineering Pseudocode and C Language Review. Example Pseudocode.

Pseudocode. Pseudocode. Guide for Pseudocode. Computers in Engineering Pseudocode and C Language Review. Example Pseudocode. Computers in Engineering Pseudocode and C Language Review Pseudocode Pseudocode is an artificial and informal language that helps you develop algorithms Pseudocode is similar to everyday English; it is

More information

5 Let s all move one place on. Lewis Carroll

5 Let s all move one place on. Lewis Carroll Control Statements: Part 2, Solutions 5 Let s all move one place on Lewis Carroll The wheel is come full circle William Shakespeare How many apples fell on Newton s head before he took the hint! Robert

More information

Tutorial No. 5 - Solution (Decision Making and Branching)

Tutorial No. 5 - Solution (Decision Making and Branching) Tutorial No. 5 - Solution (Decision Making and Branching) 1. Explain if...if ladder with flowchart [7] The if ladder is a way of putting together ifs together when multipath decisions are involved. A multipath

More information

A relational operator is used to make comparison between two expressions. All these operators are binary and require two operands.

A relational operator is used to make comparison between two expressions. All these operators are binary and require two operands. Control Structures in C++ Index Control Structures in C++ 3.1 Relational Operators A relational operator is used to make comparison between two expressions. All these operators are binary and require two

More information

Chapter 5. Selection 5-1

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

More information

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int. Java How to Program, 5/e Test Item File 1 of 5 Chapter 5 Section 5.2 5.2 Q1 Counter-controlled repetition requires a.a control variable and initial value. b.a control variable increment (or decrement).

More information

14 MAKING DECISIONS IN C

14 MAKING DECISIONS IN C 14 MAKING DECISIONS IN C 14.1 INTRODUCTION So far we have seen that in C programs the instructions are executed in the same order in which they appear in the program. Each instruction is executed once

More information

Chapter 4 C Program Control

Chapter 4 C Program Control Chapter 4 C Program Control 1 Outline 4.1 Introduction 4.2 The Essentials of Repetition 4.3 Counter-Controlled Repetition 4.4 The for Repetition Statement 4.5 The for Statement: Notes and Observations

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

Chapter 6 Repetition

Chapter 6 Repetition Chapter 6 Repetition 6-1 Repetition in C++ The final control/logic structure is repetition: Repetition repeating a block of code until a condition is met There are three repetition statements available

More information

Conditionals (with solutions)

Conditionals (with solutions) Conditionals (with solutions) For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87;

More information

PE1 Worksheet. 3) What are the three control structures for writing an algorithm in pseudocode?

PE1 Worksheet. 3) What are the three control structures for writing an algorithm in pseudocode? PE1 Worksheet Problem solving 1) What are the four stages of problem solving by programming? What shall be done in each stage? Stage 1: Stage 2: Stage 3: Stage 4: 2) What is the top-down design strategy

More information

Lecture 2 Notes: Flow of Control

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

More information

Statement-Level Control Structures

Statement-Level Control Structures Statement-Level Control Structures Introduction Selection Statements Iterative Statements Unconditional Branching Levels of Control Flow Within expressions Among program units Among program statements

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

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

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

More information

Lecture 11: while loops CS1068+ Introductory Programming in Python. for loop revisited. while loop. Summary. Dr Kieran T. Herley 2016/17.

Lecture 11: while loops CS1068+ Introductory Programming in Python. for loop revisited. while loop. Summary. Dr Kieran T. Herley 2016/17. Lecture 11: while loops CS1068+ Introductory Programming in Python Dr Kieran T. Herley Python s while loop. Summary Department of Computer Science University College Cork 2016/17 KH (02/11/16) Lecture

More information

Statements and Control Flow

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

More information

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail ALGORITHMS AND FLOWCHARTS By Miss Reham Tufail ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe

More information

Control structures in C

Control structures in C Control structures in C Lecture Topics Conditional constructs Iterative constructs Examples Style Lecture materials Textbook 13.3-13.5 Homework None Machine problem MP1.1 due February 2 at 5pm submitted

More information

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

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,

More information

FBCA-02 April-2007 Programming in C Language BCA-102 (New Course)

FBCA-02 April-2007 Programming in C Language BCA-102 (New Course) Seat No. : FBCA-02 April-2007 Programming in C Language BCA-102 (New Course) Time : 3 Hours] [Max. Marks : 70 Instructions : (1) Figures to the right indicate full marks of the question. (2) Make and state

More information

Visual Logic Instructions and Assignments

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.

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

Essentials of Counter-Controlled Repetition. Counter-controlled repetition requires:

Essentials of Counter-Controlled Repetition. Counter-controlled repetition requires: Lecture 5 Slide 1 Essentials of Counter-Controlled Repetition Counter-controlled repetition requires: Name of control variable (loop counter) Initial value of control variable Increment/decrement of control

More information

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

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

More information

4.8 Thedo while Repetition Statement Thedo while repetition statement

4.8 Thedo while Repetition Statement Thedo while repetition statement 1 4.8 hedo while Repetition Statement hedo while repetition statement Similar to thewhile structure Condition for repetition tested after the body of the loop is performed All actions are performed at

More information

Outline. Repetition (Loops) Types of Loops. Repetitions with Loops. Terminating Loops. PreTest vs. PostTest Loops. II.

Outline. Repetition (Loops) Types of Loops. Repetitions with Loops. Terminating Loops. PreTest vs. PostTest Loops. II. Repetition (Loops) Outline Want to do some repetitive sequence of actions: print vertical line of s Corresponding program: printf( \n ); printf( \n ); printf( \n ); printf( \n ); printf( \n ); II. Program

More information

COMPSCI 210 Part II Decisions & Iterations

COMPSCI 210 Part II Decisions & Iterations Agenda COMPSCI 210 Part II Decisions & Iterations Based on slides @ McGraw-Hill Agenda: Decision-making statements: he if statement he switch statement Iterations he for statement he while statement he

More information

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

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

More information

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment

More information

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

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

More information

Chapter 8. Statement-Level Control Structures

Chapter 8. Statement-Level Control Structures Chapter 8 Statement-Level Control Structures Chapter 8 Topics Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions 8-2 1 Levels of Control Flow Within

More information

Branching. We ll continue to look at the basics of writing C++ programs including. Overview

Branching. We ll continue to look at the basics of writing C++ programs including. Overview Branching Overview We ll continue to look at the basics of writing C++ programs including Boolean Expressions (need to know this before we can using branching and looping!) Branching J.S. Bradbury CSCI

More information

While Loop. 6. Iteration

While Loop. 6. Iteration While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true

More information

Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr; 50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)

More information

S206E Lecture 20, 5/24/2016, Python condition and loops

S206E Lecture 20, 5/24/2016, Python condition and loops Arch534 Spring 2016 Copyright 2016, Chiu-Shui Chan. All Rights Reserved. This lecture is the beginning of the introduction of operating logic in Python. There are three types of logical operations available

More information

CONTROL STRUCTURES AND STATEMENTS IN C AND CPP

CONTROL STRUCTURES AND STATEMENTS IN C AND CPP CONTROL STRUCTURES AND STATEMENTS IN C AND CPP Control structures form the basic entities of a structured programming language. We all know languages like C/C++ or Java are all structured programming languages.

More information

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006 Basic C Syntax Comp-206 : Introduction to Software Systems Lecture 10 Alexandre Denault Computer Science McGill University Fall 2006 Next Week I'm away for the week. I'll still check my mails though. No

More information

Chapter 5 Looping. At a Glance. Overview. Objectives. Quick Quizzes. Additional Resources. Key Terms

Chapter 5 Looping. At a Glance. Overview. Objectives. Quick Quizzes. Additional Resources. Key Terms Chapter 5 Looping At a Glance Overview Objectives Quick Quizzes Additional Resources Key Terms Lecture Notes Overview Chapter 5 covers loops in detail. Students learn the advantages of looping. They also

More information

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

System.out.println(\nEnter Product Number 1-5 (0 to stop and view summary) : Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class

More information

Two-way selection. Branching and Looping

Two-way selection. Branching and Looping Control Structures: are those statements that decide the order in which individual statements or instructions of a program are executed or evaluated. Control Structures are broadly classified into: 1.

More information

Algorithm and Flowchart. 204112 Structured Programming 1

Algorithm and Flowchart. 204112 Structured Programming 1 Algorithm and Flowchart 204112 Structured Programming 1 Programming Methodology Problem solving Coding Problem statement and analysis Develop a high-level algorithm Detail out a low-level algorithm Choose

More information

Informatica e Sistemi in Tempo Reale

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)

More information

PIC 10A. Lecture 7: Graphics II and intro to the if statement

PIC 10A. Lecture 7: Graphics II and intro to the if statement PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the

More information

JavaScript: Control Statements I

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

More information

Lecture 1 Introduction to Java

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

More information

CS 241 Data Organization Coding Standards

CS 241 Data Organization Coding Standards CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.

More information

Basic Common Unix commands: Change to directory d

Basic Common Unix commands: Change to directory d Basic Common Unix commands: cd d Change to directory d mkdir d rmdir d mv f1 [f2...] d mv d1 d2 ls [d] [f...] ls -1 [f...] vi [f] emacs [f] more f cp f1 f2 mv f1 f2 rm f gcc [-o f1] f2 gnuplot Create new

More information

Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming http://cevre.beun.edu.tr/zeydan/

Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming http://cevre.beun.edu.tr/zeydan/ Algorithms Pseudocode Flowcharts (PhD) CIV 112 Computer Programming http://cevre.beun.edu.tr/zeydan/ Why do we have to learn computer programming? Computers can make calculations at a blazing speed without

More information

C Programming Lecture IV

C Programming Lecture IV C Programming Lecture IV Instructor Özgür ZEYDAN http://cevre.beun.edu.tr/ break and continue Statements break statement is used to terminate any type of loop such as while loop, do while loop and for

More information

CS1010 Programming Methodology A beginning in problem solving in Computer Science. Aaron Tan http://www.comp.nus.edu.sg/~cs1010/ 20 July 2015

CS1010 Programming Methodology A beginning in problem solving in Computer Science. Aaron Tan http://www.comp.nus.edu.sg/~cs1010/ 20 July 2015 CS1010 Programming Methodology A beginning in problem solving in Computer Science Aaron Tan http://www.comp.nus.edu.sg/~cs1010/ 20 July 2015 Announcements This document is available on the CS1010 website

More information

while for ! do while ! set an accumulator variable to 0 ! add the next number to it inside the loop

while for ! do while ! set an accumulator variable to 0 ! add the next number to it inside the loop Week 7: Advanced Loops while Loops in C++ (review) while (expression) statement statement may be a compound statement (a block: {statements) Gaddis: 5.7-12 CS 1428 Fall 2014 Jill Seaman 1 for if expression

More information

Program Logic to Java GEEN163

Program Logic to Java GEEN163 Program Logic to Java GEEN163 In theory, theory and practice are the same. In practice, they're not. Yogi Berra Founders' Day The Founders' Day Convocation is Thursday, March 21 from 10:00 12:00 in the

More information

Keil C51 Cross Compiler

Keil C51 Cross Compiler Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation

More information

JavaScript: Control Statements II

JavaScript: Control Statements II JavaScript: Control Statements II 6.2 Essentials of Counter-Controlled Repetition 6.3 for Repetition Statement 6.4 Examples Using the for Statement 6.5 switch Multiple-Selection Statement 6.6 do while

More information

Solutions to Assessment: Basic Programming Constructs

Solutions to Assessment: Basic Programming Constructs Solutions to Assessment: Basic Programming Constructs Question 1: Specify the minimum number of comparisons required to find the largest number among a set of 3 integers X, Y and Z. We already know how

More information

Module 1: Propositional Logic. CPSC 121: Models of Computation. Module 1: Coming up... Module 1: Coming up...

Module 1: Propositional Logic. CPSC 121: Models of Computation. Module 1: Coming up... Module 1: Coming up... CPSC 121: Models of Computation By the start of the class, you should be able to: Translate back and forth between simple natural language statements and propositional logic. Evaluate the truth of propositional

More information

Chapter 3: Control Structures

Chapter 3: Control Structures Chapter 3: Control Structures 1. Higher order organization of Python instructions In the previous chapters, we have introduced the different types of variables known by Python, as well as the operators

More information

Software II: Principles of Programming Languages

Software II: Principles of Programming Languages Software II: Principles of Programming Languages Lecture 8 Statement-Level Control Structures Control Statements: Evolution FORTRAN I control statements were based directly on IBM 704 hardware Much research

More information

Do not open this examination paper until instructed to do so. Section A: answer all the questions. Section B: answer all the questions.

Do not open this examination paper until instructed to do so. Section A: answer all the questions. Section B: answer all the questions. N10/5/COMSC/HP1/ENG/TZ0/XX 88107011 Computer science HIGHER level Paper 1 Tuesday 16 November 2010 (afternoon) 2 hours 15 minutes INSTRUCTIONS TO CANDIDATES Do not open this examination paper until instructed

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

UEE1302 (1102) F10 Introduction to Computers and Programming

UEE1302 (1102) F10 Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU UEE1302 (1102) F10 Introduction to Computers and Programming Programming Lecture 03 Flow of Control (Part II): Repetition while,for & do..while Learning

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 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

More information

Reading Assignment Control Flow Statements switch while for break continue Scopes of Declaration Scopes and Visibility Good Style: smallest scope

Reading Assignment Control Flow Statements switch while for break continue Scopes of Declaration Scopes and Visibility Good Style: smallest scope Reading Assignment Control Flow Statements Scopes of Declaration K.N. King, Chapter 8 Assert function Grouping: and Decision making: if, switch Loop building: while, do, for Loop ending: break, continue

More information

Lecture 9 verifying temporal logic

Lecture 9 verifying temporal logic Basics of advanced software systems Lecture 9 verifying temporal logic formulae with SPIN 21/01/2013 1 Outline for today 1. Introduction: motivations for formal methods, use in industry 2. Developing models

More information

Adding and Subtracting Positive and Negative Numbers

Adding and Subtracting Positive and Negative Numbers Adding and Subtracting Positive and Negative Numbers Absolute Value For any real number, the distance from zero on the number line is the absolute value of the number. The absolute value of any real number

More information

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook. Elementary Number Theory and Methods of Proof CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.edu/~cse215 1 Number theory Properties: 2 Properties of integers (whole

More information

Conditional and Looping Construct

Conditional and Looping Construct Chapter 3 Conditional and Looping Construct After studying this lesson, students will be able to: Understand the concept and usage of selection and iteration statements. Know various types of loops available

More information

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011 6.096 Lab 1 Due: 7 January 1:30:00 September 0, 011 1 Additional Material 1.1 Constants A constant is an expressions with a fixed value. Kinds of constants: Literals: used to express particular values

More information

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control Reading: Bowman, Chapters 16 CODE BLOCKS A code block consists of several lines of code contained between a BEGIN

More information

Chapter 8. Statement-Level Control Structures ISBN

Chapter 8. Statement-Level Control Structures ISBN Chapter 8 Statement-Level Control Structures ISBN 0-321-33025-0 Chapter 8 Topics Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions Copyright 2006

More information

6. Control Structures

6. Control Structures - 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

More information

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

Chapter 4 Operators & Arithmetic

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)

More information

LAB 4 SELECTION STRUCTURES

LAB 4 SELECTION STRUCTURES LAB 4 SELECTION STRUCTURES School of Computer and Communication Engineering Universiti Malaysia Perlis 1 1. OBJECTIVES: 1.1 Introduction to if, if., nested if and switch statements. 1.2 Able to use selection

More information

What does the following code print? (Assume the program compiles without error). Trick question! Note the semicolon at the end of the second line.

What does the following code print? (Assume the program compiles without error). Trick question! Note the semicolon at the end of the second line. All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers

More information

DISCRETE MATH: LECTURE 4

DISCRETE MATH: LECTURE 4 DISCRETE MATH: LECTURE 4 DR. DANIEL FREEMAN 1. Chapter 3.1 Predicates and Quantified Statements I A predicate is a sentence that contains a finite number of variables and becomes a statement when specific

More information

Chapter 8 Selection 8-1

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

More information

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Midterm Examination October 27, 2009 12:20 p.m. 1:50 p.m. Examiners: J. Anderson, T. Fairgrieve, H. Ghaderi,

More information

Topic 11 Scanner object, conditional execution

Topic 11 Scanner object, conditional execution Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright

More information

CS 101: Computer Programming and Utilizati on

CS 101: Computer Programming and Utilizati on CS 101: Computer Programming and Utilizati on Jul-Nov 2016 Bernard Menezes (cs101@cse.iitb.ac.in) Lecture 5: Conditional Execution About These Slides Based on Chapter 6 of the book An Introduction to Programming

More information

1. A(n) structure is a logical design that controls the order in which a set of statements execute. a. function b. control c. sequence d.

1. A(n) structure is a logical design that controls the order in which a set of statements execute. a. function b. control c. sequence d. Chapter Four MULTIPLE CHOICE 1. A(n) structure is a logical design that controls the order in which a set of statements execute. a. function b. control c. sequence d. iteration 2. The decision structure

More information

Writing Control Structures

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

More information

C# programming. Introduction. By Per Laursen

C# programming. Introduction. By Per Laursen C# programming Introduction By Per Laursen Indhold The Programming Process... 3 Environment... 5 Statements... 7 Programming Fundamentals... 9 Types and Variables... 10 Simple data output on the screen...

More information