1 Flowchart If – Then – Else อนันต์ ผลเพิ่ม Anan Phonphoem

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

Selection Process If … then … else.... Condition Process 2 Process 1 Y.
Selection If Flowchart A diagram that shows step-by-step progression through a procedure or system especially using connecting lines and a set of conventional.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Flow Control Analysis & Design Tool: Flowcharts
Mathematics for Computing Lecture 4: Algorithms and flowcharts Dr Andrew Purkiss-Trew Cancer Research UK
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Chapter 4: Control Structures: Selection
Developing logic (Examples on algorithm and flowchart)
ALGORITHMS AND FLOWCHARTS
Expressions creating information. topics  operators: precedence, associativity, parentheses, overloading  operands: side-effects, coercion  arithmetic,
Computer Science 101 The Boolean System. George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if.
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Computer Science Selection Structures.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Pascal language Slides of Omar Al-Nahal. Components of Pascal Language Components of Pascal Language 1. Pascal Character set: - English Letters. - Decimal.
Selection Boolean What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean.
INFORMATION TECHNOLOGY CSEC CXC 10/25/ PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.
Flowcharts.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 6, Lecture 1 (Monday)
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 Programming with MATLAB ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Arithmetic in Pascal A Short Glance We will learn the followings in this chapter Arithmetic operators Order of precedence Assignment statements Arithmetic.
Arithmetic Expressions
Basic Control Structures
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
CMSC 104, Section 301, Fall Lecture 17, 11/04/02 Homework 4a and 4b Topics Go over Homework 4a Problems , Problems Go over.
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Control statements Mostafa Abdallah
CPS120: Introduction to Computer Science Decision Making in Programs.
1 Conditional Statements + Loops ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
Sum of Arithmetic Sequences. Definitions Sequence Series.
1 for – while – switch ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
Array : 1-dimension อนันต์ ผลเพิ่ม Anan Phonphoem
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Multidimensional Array: อนันต์ ผลเพิ่ม Anan Phonphoem
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
2 nd Semester Module3 Selection Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Introduction to Flowcharts
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
 Type Called bool  Bool has only two possible values: True and False.
Flowchart Symbols Terminal Process Input/ Output Decision
Sequence, Selection, Iteration The IF Statement
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
Data Types, Identifiers, and Expressions
Operator Precedence Operators Precedence Parentheses () unary
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Outline Altering flow of control Boolean expressions
Relational Operators Operator Meaning < Less than > Greater than
kbkjlj/m/lkiubljj'pl;
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
Faculty of Computer Science & Information System
ME 142 Engineering Computation I
Visual Basic – Decision Statements
Summary Two basic concepts: variables and assignments Basic types:
Expressions.
Presentation transcript:

1 Flowchart If – Then – Else อนันต์ ผลเพิ่ม Anan Phonphoem

2 Outline Flowcharts IF – THEN – ELSE

3 Boolean Expression Two possible values: True, False 1.Relation Operator =,, <>, = 2.Boolean Operator AND, OR, NOT 15 = 34 False < 17 True True

4 Precedence rules for arithmetic operators 1.( ) parentheses 2.Unary + and – 3.*, /, DIV, MOD 4.+ – 5.If equal precedence, left to right Examples -a+j/-w = (-a) + (j / (-w)) C*23/6+23mod2 = ((C*23)/6) + (23 mod 2)

5 Precedence rules for Boolean Operators 1.( ) parentheses 2.NOT 3.and 4.Or 5., 6.If equal precedence, left to right Examples (count <= 10) AND (Sum <= Limit) OR NOT Stop

6 Flowcharts Graphical representation of algorithm Terminator Process Input/output Decision Connector Flow line

7 Flowchart example Start Read width Read length Total := width + length If total 0 Write total End No Yes

8 IF – THEN IF condition THEN statement condition False True Statement

9 IF – Then (sum1.pas) Program summation1; Var Sum, number : integer; Begin Sum := 10; Write ( ‘ Please input a number ’ ); Readln(number); if number < 0 then number := 0; Sum := Sum + number; writeln ( ‘ Sum = ‘, Sum) End.

10 IF – THEN – ELSE IF condition THEN statement 1 ELSE statement 2 condition FalseTrue Statement2Statement1

11 IF – Then – Else (sum2.pas) Program summation2; Var Sum, number : integer; Begin Sum := 10; Write ( ‘ Please input a number ’ ); Readln(number); if number < 0 then number := 0; else number := 20; Sum := Sum + number; writeln ( ‘ Sum = ‘, Sum) End.

12 Nested Logic condition1 False True Statement1 condition2 FalseTrue Statement3Statement2 IF cond1 THEN statement1 ELSE IF cond2 THEN Statement2 ELSE statement3

13 Nested Logic (Sum3.pas) Begin Sum := 10; Write ( ‘ Please input a number ’ ); Readln(number); if number > 0 then number := number +1; if number > 5 then number := 5; else number := 20; Sum := Sum + number; writeln ( ‘ Sum = ‘, Sum) End.

14 Nested Logic (sum4.pas) Begin Sum := 10; Write ( ‘ Please input a number ’ ); Readln(number); if number > 0 then begin number := number +1; if number > 5 then number := 5; End else number := 20; Sum := Sum + number; writeln ( ‘ Sum = ‘, Sum) End.

15 Case Case expression of const_value1 : statement1; const_value2 : statement2; const_value3 : statement3; Else statement4; End;

16 Case Example Readln (number); Case number of 1,2,3 : writeln( ‘ small ’ ); 4,5,6 : writeln( ‘ medium ’ ); 7,8 : writeln ( ‘ large ’ ); End;