ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail



Similar documents
ALGORITHMS AND FLOWCHARTS

Algorithms, Flowcharts & Program Design. ComPro

Computer Programming Lecturer: Dr. Laith Abdullah Mohammed

Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Flowchart Techniques

Computer Programming

1.3 Algebraic Expressions

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

Solving Quadratic Equations by Factoring

Flowcharting, pseudocoding, and process design

Chapter 1 An Introduction to Computers and Problem Solving

FACTORING QUADRATICS and 8.1.2

COLLEGE ALGEBRA 10 TH EDITION LIAL HORNSBY SCHNEIDER 1.1-1

JavaScript: Control Statements I

2 SYSTEM DESCRIPTION TECHNIQUES

4.1. COMPLEX NUMBERS

IV. ALGEBRAIC CONCEPTS

A Systematic Approach to Factoring

Notes on Algorithms, Pseudocode, and Flowcharts

Visual Logic Instructions and Assignments

Sect Solving Equations Using the Zero Product Rule

2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:

CS 241 Data Organization Coding Standards

Grade 5 Common Core State Standard

I PUC - Computer Science. Practical s Syllabus. Contents

Chapter R.4 Factoring Polynomials

How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.

Exercise Worksheets. Copyright Susan D. Phillips

Chapter One Introduction to Programming

MATH 21. College Algebra 1 Lecture Notes

LINEAR INEQUALITIES. Mathematics is the art of saying many things in many different ways. MAXWELL

Answer Key for California State Standards: Algebra I

MA107 Precalculus Algebra Exam 2 Review Solutions

Factoring Polynomials

Factoring Quadratic Expressions

Chapter 5. Selection 5-1

Math 0980 Chapter Objectives. Chapter 1: Introduction to Algebra: The Integers.

Mathematics Georgia Performance Standards

ALGEBRA 2: 4.1 Graph Quadratic Functions in Standard Form

3.2. Solving quadratic equations. Introduction. Prerequisites. Learning Outcomes. Learning Style

Linear Equations in One Variable

Learning Objectives 9.2. Media Run Times 9.3

2x 2x 2 8x. Now, let s work backwards to FACTOR. We begin by placing the terms of the polynomial inside the cells of the box. 2x 2

Tool 1. Greatest Common Factor (GCF)

Factoring Polynomials and Solving Quadratic Equations

Definitions 1. A factor of integer is an integer that will divide the given integer evenly (with no remainder).

Factoring and Applications

1.3. DOT PRODUCT If θ is the angle (between 0 and π) between two non-zero vectors u and v,

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

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

CCSS Mathematics Implementation Guide Grade First Nine Weeks

9.3 OPERATIONS WITH RADICALS

How To Solve Factoring Problems

VB Controls and Events. Introduc)on. Program Planning and Flowcharts Visual Basic Visual basic Interface VB Controls CreaGng a Project

Problem Solving Basics and Computer Programming

Chapter 8 Selection 8-1

Software development and programming. Software

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

expression is written horizontally. The Last terms ((2)( 4)) because they are the last terms of the two polynomials. This is called the FOIL method.

7.2 Quadratic Equations

Solving Quadratic Equations

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

This unit will lay the groundwork for later units where the students will extend this knowledge to quadratic and exponential functions.

CORRELATED TO THE SOUTH CAROLINA COLLEGE AND CAREER-READY FOUNDATIONS IN ALGEBRA

Programming Logic and Design Eighth Edi(on

APPLICATIONS AND MODELING WITH QUADRATIC EQUATIONS

Pseudo code Tutorial and Exercises Teacher s Version

MATH 0110 Developmental Math Skills Review, 1 Credit, 3 hours lab

Application. Outline. 3-1 Polynomial Functions 3-2 Finding Rational Zeros of. Polynomial. 3-3 Approximating Real Zeros of.

Definition 8.1 Two inequalities are equivalent if they have the same solution set. Add or Subtract the same value on both sides of the inequality.

CAMI Education linked to CAPS: Mathematics

Factoring Trinomials: The ac Method

3.6. Partial Fractions. Introduction. Prerequisites. Learning Outcomes

Fundamentals of Programming and Software Development Lesson Objectives

1 BPS Math Year at a Glance (Adapted from A Story of Units Curriculum Maps in Mathematics P-5)

1st Grade Math Standard I Rubric. Number Sense. Score 4 Students show proficiency with numbers beyond 100.

Algebra Practice Problems for Precalculus and Calculus

BEGINNING ALGEBRA ACKNOWLEDMENTS

Grade descriptions Computer Science Stage 1

CONVERT QUADRATIC FUNCTIONS FROM ONE FORM TO ANOTHER (Standard Form <==> Intercept Form <==> Vertex Form) (By Nghi H Nguyen Dec 08, 2014)

FACTORING QUADRATIC EQUATIONS

15.1 Factoring Polynomials

Factors and Products

3.3. Solving Polynomial Equations. Introduction. Prerequisites. Learning Outcomes

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

What are the place values to the left of the decimal point and their associated powers of ten?

ModuMath Basic Math Basic Math Naming Whole Numbers Basic Math The Number Line Basic Math Addition of Whole Numbers, Part I

Chapter 4 -- Decimals

1 Lecture: Integration of rational functions by decomposition

Math 0306 Final Exam Review

Prentice Hall: Middle School Math, Course Correlated to: New York Mathematics Learning Standards (Intermediate)

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

26 Integers: Multiplication, Division, and Order

Notes on Determinant

Florida Algebra 1 End-of-Course Assessment Item Bank, Polk County School District

A.2. Exponents and Radicals. Integer Exponents. What you should learn. Exponential Notation. Why you should learn it. Properties of Exponents

Math 10C. Course: Polynomial Products and Factors. Unit of Study: Step 1: Identify the Outcomes to Address. Guiding Questions:

( ) FACTORING. x In this polynomial the only variable in common to all is x.

Transcription:

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 solution of problem this sequence of steps is called an algorithm Implementation phase implement the program in some programming language

Steps in Problem Solving First produce a general algorithm (one can use pseudocode) Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language. Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is very similar to everyday English.

Pseudocode & Algorithm Example 1: Write an algorithm to determine a student s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

Pseudocode & Algorithm Pseudocode: Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print FAIL else Print PASS

Pseudocode & Algorithm Detailed Algorithm Step 1: Input M1,M2,M3,M4 Step 2: GRADE (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print FAIL else Print PASS endif

The Flowchart (Dictionary) A schematic representation of a sequence of operations, as in a manufacturing process or computer program. (Technical) A graphical representation of the sequence of operations in an information system or program. Information system flowcharts show how data flows from source documents through the computer to final distribution to users. Program flowcharts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart.

The Flowchart A Flowchart shows logic of an algorithm emphasizes individual steps and their interconnections e.g. control flow from one action to the next

Flowchart Symbols Basic Name Symbol Use in Flowchart Oval Denotes the beginning or end of the program Parallelogram Denotes an input operation Rectangle Denotes a process to be carried out e.g. addition, subtraction, division etc. Diamond Denotes a decision (or branch) to be made. The program should continue along one of two routes. (e.g. IF/THEN/ELSE) Hybrid Denotes an output operation Flow line Denotes the direction of logic flow in the program

Example START Input M1,M2,M3,M4 GRADE (M1+M2+M3+M4)/4 Step 1: Input M1,M2,M3,M4 Step 2: GRADE (M1+M2+M3+M4)/4 Step 3: if (GRADE <50) then Print FAIL else Print PASS endif N IS GRADE<5 0 Y PRINT PASS PRINT FAIL STOP

Example 2 Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Pseudocode: Input the length in feet (Lft) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM)

Example 2 Algorithm Step 1: Input Lft Step 2: Lcm Lft x 30 Step 3: Print Lcm Flowchart START Input Lft Lcm Lft x 30 Print Lcm STOP

Example 3 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudocode Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A

Example 3 Algorithm Step 1: Input W,L Step 2: A L x W Step 3: Print A START Input W, L A L x W Print A STOP

Example 4 Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation 2 ax bx c 0 2 Hint: d = sqrt ( b 4ac ), and the roots are: x1 = ( b + d)/2a and x2 = ( b d)/2a

Example 4 Pseudocode: Input the coefficients (a, b, c) of the quadratic equation Calculate d Calculate x1 Calculate x2 Print x1 and x2

Example 4 Algorithm: Step 1: Input a, b, c b b 4 a c Step 2: d sqrt ( ) Step 3: x1 ( b + d) / (2 x a) Step 4: x2 ( b d) / (2 x a) Step 5: Print x1, x2 START Input a, b, c d sqrt(b x b 4 x a x c) x 1 ( b + d) / (2 x a) X 2 ( b d) / (2 x a) Print x 1,x 2 STOP

DECISION STRUCTURES The expression A>B is a logical expression it describes a condition we want to test if A>B is true (if A is greater than B) we take the action on left print the value of A if A>B is false (if A is not greater than B) we take the action on right print the value of B

DECISION STRUCTURES Y is A>B N Print A Print B

IF THEN ELSE STRUCTURE The structure is as follows If condition then true alternative else false alternative endif

IF THEN ELSE STRUCTURE The algorithm for the flowchart is as follows: If A>B then print A else print B endif Y Print A is A>B N Print B

Relational Operators Relational Operators Operator Description > Greater than < Less than = Equal to Greater than or equal to Less than or equal to Not equal to

Example 5 Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. ALGORITHM Step 1: Step 2: Step 3: Input VALUE1, VALUE2 if (VALUE1 > VALUE2) then MAX VALUE1 else MAX VALUE2 endif Print The largest value is, MAX

Example 5 START Input VALUE1,VALUE2 Y is VALUE1>VALUE2 N MAX VALUE1 MAX VALUE2 Print The largest value is, MAX STOP

NESTED IFS One of the alternatives within an IF THEN ELSE statement may involve further IF THEN ELSE statement

Example 6 Write an algorithm that reads three numbers and prints the value of the largest number.

Example 6 Step 1: Input N1, N2, N3 Step 2: if (N1>N2) then if (N1>N3) then MAX N1 [N1>N2, N1>N3] else MAX N3 [N3>N1>N2] endif else if (N2>N3) then MAX N2 [N2>N1, N2>N3] else MAX N3 [N3>N2>N1] endif endif Step 3: Print The largest number is, MAX

Example 6 (Assignment) Flowchart: Draw the flowchart of the above Algorithm.

While Loop

Do While Loop

For Loop

Switch Statement

Class Exercises You are required to design an algorithm for finding the average of six numbers, and the sum of the numbers is given.

Pseudocode Start Get the sum Average = sum / 6 Output the average Stop

Class Exercises Write algorithm and draw flowchart to Add two Numbers.

Class Exercises Write algorithm and draw flowchart to Display your Age

Assignment Write an algorithm and draw a flowchart to read 100 numbers and then display the sum Write an algorithm and draw a flowchart to read two numbers then display the smallest Write (Display) the Sum, Average and Product