ALGORITHMS Algorithm: Is an ordered set of unambiguous, executable steps defining a terminating process Unambiguous:during the execution of an algorithm,

Slides:



Advertisements
Similar presentations
PROBLEM SOLVING TECHNIQUES
Advertisements

Repetition Control Structures
INTRODUCTION TO PROGRAMMING
 Control structures  Algorithm & flowchart  If statements  While statements.
 2002 Prentice Hall. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection Statement 4.6 if else Selection Statement 4.7 while.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
Structured Program Development in C
Lecture 3 Structured Program Development in C
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
ALGORITHMS AND FLOWCHARTS
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
Pseudocode algorithms using sequence, selection and repetition
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
Jaeki Song ISQS6337 JAVA Lecture 04 Control Structure - Selection, and Repetition -
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Algorithm & Flow Charts
PSEUDOCODE C Programming Technique – Firdaus-Harun.com.
C Lecture Notes 1 Structured Program Development.
C++ Programming Lecture 6 Control Structure II (Repetition) By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Chapter 2: General Problem Solving Concepts
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure 4.6 The if / else Selection Structure 4.7.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Basic Control Structures
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Unit 2 – Algorithms & Pseudocode. Algorithms Computer problems solved by executing series of action in order Procedure –The Actions to execute –The Order.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
1 JavaScript: Control Structures. 2 Control Structures Flowcharting JavaScript’s sequence structure.
1 Lecture 3 Control Structures else/if and while.
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
Program design Program Design Process has 2 phases:
Problem Solving & Computer Programming
ALGORITHMS AND FLOWCHARTS
Algorithm: procedure in terms of
while Repetition Structure
ALGORITHMS AND FLOWCHARTS
CS111 Computer Programming
Algorithms and Flowcharts
Chapter 4: Control Structures
Ch 7: JavaScript Control Statements I.
Control Statements Kingdom of Saudi Arabia
Chapter 4 – Control Structures Part 1
Programming Fundamentals
ALGORITHMS AND FLOWCHARTS
Pseudocode algorithms using sequence, selection and repetition
MSIS 655 Advanced Business Applications Programming
Structured Program
Chapter 3 - Structured Program Development
ALGORITHMS AND FLOWCHARTS
3 Control Statements:.
Chapter 3 - Structured Program Development
2.6 The if/else Selection Structure
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
EPSII 59:006 Spring 2004.
Presentation transcript:

ALGORITHMS Algorithm: Is an ordered set of unambiguous, executable steps defining a terminating process Unambiguous:during the execution of an algorithm, the information in the state of the process must be sufficient to determine uniquely and completely the action required by each step

ALGORITHMS Or The execution of each step in an algorithm does not require creative skills. Rather, it requires only the ability to follow directions.

Control Structures The key to clear algorithm design lies in limiting the control structure to only three structures: Sequence, Selection, & Repetition The following are the basic C and C++ control structures illustrated in flowchart and statement form:

1) Sequence : Example: C=A+B

2) Selection: if & if/else if/else Structure(Double Selection) if Structure (Single Selection) T F

2) Selection: switch Break T F Switch Structure(Multiple Selection)

3) Repetition: while & do/while do/while structure T F while Structure T F

3) Repetition: for loop T F for Structure

Pseudocode: There are several ways to represent algorithms. Such as pseudocode, flowcharts, … Pseudocode: Individual operations are described briefly and precisely in English standard statements consists of nouns and verbs

Pseudocode: For example, to evaluate the formula for converting temperature reading from Celsius to Fahrenheit: F= (9 /5) C + 32 Solution: Algorithm in pseudocode: Get the value of C Calculate F Print F

While the flowchart used is shown bellow (the used control structure is Sequence ): Start Read C F=(9/5)C+32 Print F End

Example 1 : Write an algorithm and draw a flowchart to read the grades of five students , find the average of these grades and print it Counter=1 total=0,average=0 If Counter<5 Read Grade Total=Total+grade Average=Total/5 End START T F Print Average Counter=Counter+1 Algorithm: Initialize counter to 1 Initialize total to zero Initialize average to zero While counter is less than or equal 5 Input the grade Add grade into total average=total/5 Print average

Example2: A student took final exams of 10 courses Example2: A student took final exams of 10 courses. Write an algorithm and draw a flowchart to read the grades and find their sum and print it. START Count=1 Total=0 If Count<10 Read Grade Print Total Total=Total+Grade END Count=Count+1 T F Algorithm: Initialize Count to 1 Initialize Total to Zero For Count=1 to 10 Read a Grade Add Grade to Total Print Total

Example 3 : Write an algorithm and draw a flowchart to read a grade, test it if PASS(more than or equal 50) or FAIL, and print the result . START Read Grade If Grade>50 Print”PASS” Print”FAIL” END T F Algorithm : Read a Grade If Grade more than or equal 50 Print PASS Else Print FAIL