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

Post on 27-Mar-2015

231 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

Transcript

Unit 1, Part 2

Introduction toC 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”

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

Diamond Shape – Decision Point

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

Contains one question, with yes/no answer

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

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

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

Shapes Combine to Create Structures

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

Straight-line Structure

Single-sided Branch

Double-sided Branch

Selection Structure Selection structure is an extension of the

branch All branches must converge together at the

end

“Do-While” Loop

“While” Loop

“Until” Loop

Flowchart Examples

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

Flowchart Created from Algorithm

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

Flowchart for Odd Numbers < 10

top related