unit 1, part 2 introduction to c programming. flowchart elements unit 1: algorithms

21
Unit 1, Part 2 Introduction to C Programming

Upload: destiny-lindsey

Post on 27-Mar-2015

235 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Unit 1, Part 2

Introduction toC Programming

Page 2: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Flowchart Elements

Unit 1: Algorithms

Page 3: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Begin and End Shapes These shapes are used to begin and end a

flowchart The beginning shape has the algorithm

name as its label The end shape contains the word “End”

Page 4: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Rectangle Shape – Actions Rectangle has one entry and one exit The text in the rectangle is pseudo-code

corresponding to one step in the algorithm

Page 5: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Diamond Shape – Decision Point

One entry, two exits (one for “yes”, the other for “no”)

Contains one question, with yes/no answer

Page 6: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Selection Shape Selection is an extension of the decision

point Instead of a question, the diamond contains

a value The value selects which branch to take One “other” branch is used for all other

values that don’t have a branch

Page 7: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Connector Shape – On-page Use for a connection on same page Shape shows connection from one point to

another

Left shape can be used multiple times Right shape, used once, shows the destination

of connection

Page 8: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Connector Shape – Off-page Use for a flowchart larger than one page Shape shows connection from one page to another

Left shape can be used multiple times Right shape, used once, shows the destination of

connection Visio automatically creates a new page when this

shape used

Page 9: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Shapes Combine to Create Structures

Straight-line structure Single-sided branch Double-sided branch Selection structure Until loop While loop Do-while loop

Page 10: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Straight-line Structure

Page 11: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Single-sided Branch

Page 12: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Double-sided Branch

Page 13: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Selection Structure Selection structure is an extension of the

branch All branches must converge together at the

end

Page 14: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

“Do-While” Loop

Page 15: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

“While” Loop

Page 16: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

“Until” Loop

Page 17: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Flowchart Examples

Unit 1: Algorithms

Page 18: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Flowchart Example – Count to 9

Here is an algorithm, in pseudo code, to output 1-9:1.Output “List of Numbers less than 10”2.Put 1 in number3.Output number4.Add 1 to number5.If number is less than 10, go back to step 36.End

Page 19: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Flowchart Created from Algorithm

Page 20: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Flowchart Example – Odd #s < 10

1. Output “List of Odd Numbers less than 10”

2. Put 1 in number3. If number divided by 2 has remainder 0,

go to step 54. Output number5. Add 1 to number6. If number is less than 10, go back to step

37. End

Page 21: Unit 1, Part 2 Introduction to C Programming. Flowchart Elements Unit 1: Algorithms

Flowchart for Odd Numbers < 10