Basic Control Structures

Slides:



Advertisements
Similar presentations
Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
PREPARED BY OMPRAKASH BEHERA (A) & Group CLASS VIII JNV, DEOGARH GUIDED BY MR. PRAHALLAD BADAPANDA FCSA.
UNIT 2. Introduction to Computer Programming
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Algorithm and Flowchart Questions
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Chapter 2: Algorithm Discovery and Design
Program Design and Development
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Developing logic (Examples on algorithm and flowchart)
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
ALGORITHMS AND FLOWCHARTS
DCT 1123 Problem Solving & Algorithms
Dr. Andy Seddon Staffordshire UNIVERSITY School of Computing Code Design (The use of pseudo code for Elementary Process Descriptions)
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Logic Problems This is an assignment. There are no speaker notes.
Flowcharts.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
OPERATIONS USING FRACTIONS. 1. Add, subtract, multiply and divide fractions with and without a calculator. 2. Convert between equivalent forms of fractions.
Agenda Basic Logic Purpose if statement if / else statement
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Chapter 4 Control Structures: Selection We introduced the three fundamental control structures from which all programs are developed: 1. Sequence structures.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
ARITHMETIC OPERATORS COMPARISON/RELATIO NAL OPERATORS LOGIC OPERATORS ()Parenthesis>Greater than &&And ^Exponentiation=>=
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Introduction to Flowcharts
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Program design Program Design Process has 2 phases:
Flowchart Symbols Terminal Process Input/ Output Decision
Making Choices with if Statements
Be A programmer in Steps
PROGRAM CONTROL STRUCTURE
Operator Precedence Operators Precedence Parentheses () unary
Think What will be the output?
C# and the .NET Framework
Ch 7: JavaScript Control Statements I.
CHAPTER 2 & 3: Pseudocode and Developing and Algorithm
ALGORITHMS AND FLOWCHARTS
Selection CIS 40 – Introduction to Programming in Python
Pseudocode.
CS1100 Computational Engineering
Algorithms & Pseudocode
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
` Structured Programming & Flowchart
Introduction to Programming Using Python PART 2
Summary Two basic concepts: variables and assignments Basic types:
Chapter 5: Control Structure
Computer Science Core Concepts
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
Chapter 3: Selection Structures: Making Decisions
Program Flow.
Chapter 3: Selection Structures: Making Decisions
REPETITION Why Repetition?
Presentation transcript:

Basic Control Structures Sequence Selection Repetition

Sequence A process executed from one to another in a straightforward manner.

Example of Sequence Design a flowchart that will accept and display a number. Write its equivalent algorithms. Algorithm: Step 1: Read in the value of N. Step 2: Print the value of N. Start Read N Print N End

Example of Sequence 2. Draw a flowchart that will compute and display the sum and product of two numbers. Write its equivalent algorithm. Start Sum=0 Product=0 Read A,B Sum=A+B Product=A*B Print Sum, Product End Algorithm: Step 1:Initialize Sum and Product into 0. Step 2: Read in the values of A and B. Step 3. Compute Sum by adding A and B then compute Product by multiplying A and B. Step 4: Print the computed value of Sum and Product.

Selection (if – then – else) A choice is provided between alternatives. C A B T F

Example of Selection Draw a flowchart that will input values for A and B. Compare two values inputted and print which of the values is higher including the remarks “Higher”. Write its equivalent algorithm.

Algorithm: Step 1: Read in the values of A and B. Step 2: Test if A is greater than B, A is higher. However, If A is less than B, B is higher. Step 3: Print the number and the remark “Higher”. Start Input A, B A > B Print B, Higher Print A, “Higher” End T F

Repetition (Looping) This structure provides for the repetitive execution of an operation or routine while the condition is true. The condition is evaluated before executing any process statement. As long as the condition is true, the process is executed, otherwise, control flows out of the structure.

C A F T Loop

Example of Repetition (Looping) Construct a flowchart that will count from 1 to 10 and print each number counted using the do-while-repetition structure .Write its equivalent algorithm.

Example of Repetition (Looping) Start C=0 C < 10 C = C + 1 F T Print C End Algorithm: Step 1: Initialize the value of C to 0. Step 2: Test if C is less than 10. Step 3: If C is less than 10, add 1 to the value of C, print the value then go back to Step 2. However, if C is greater than 10, stop processing.

Commonly Used Operators in Flowcharting Arithmetic Operators + addition - Subtraction * Multiplication / Division

Commonly Used Operators in Flowcharting Relational Operators = equal > Greater than < less than <> Not equal > Greater than or equal to < less than or equal to

Commonly Used Operators in Flowcharting Logical operators && AND || OR ! NOT