P.Lecture - 1.24.08

# P.Lecture - 1.24.08 - Announcements Assignment 1 due...

This preview shows pages 1–9. Sign up to view the full content.

nnouncements Announcements ssignment 1 due tonight Assignment 1 due tonight Blackboard assignment manager ore on Blackboard discussion oard More on Blackboard discussion board getchar() For today: Introduction to algorithm design using flowcharts or pseudocode notation Program control statements (Ch. 5 & 6)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Program control logic • More complex problems require situational decision gic that provides alternative paths of execution: logic that provides alternative paths of execution: 1. Instructions done in sequence (what we have seen so far) can be grouped )g p 2. Selection among alternative paths of execution 3. Iteration/repetition of a set of instructions • C has several types of statements for implementing these capabilities • But first we need to understand these at the program design level
Flowchart Symbology 101 Design Primitives Program g start/stop Control flow Process step/ function/ ction Decision Point action Input/output connector These are used to create a flowchart for algorithm design

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Three Basic Logic Constructs sequence iteration selection condition T condition F F T . . . one or a block of statements grouped together
Three Basic Logic Constructs pseudocode style quence eration lection sequence 1. … iteration 1. Repeat below steps while me ndition true selection 1.If condition is true en 2. … 3…. some condition is true a) b) c) then else end repeat 2. … 3. … end if 2. … 3. … Use indentation to see the block and logic structure

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Program Control Statements t lli th fl f th li Controlling the flow of the program’s logic •Selection - deciding among alternative execution aths paths –Boolean values, variables and logical expressions (T/F) • hese are onditions at are tested by your program These are conditions that are tested by your program –Using if and if…else statements –Nested and cascaded if statements –Using switch statements –Conditional Operators - don’t use •Iteration - repetition of statement(s) –Looping idioms: while, do, and for statements –Nested loops –Using break and continue statements
Logical Expressions lational tests relational tests The relational operators are: < less than > greater than <= less than or equal >= greater than or equal The value of a relational expression is either 1 (if the condition is ue) or f it is false): true) or 0 (if it is false): 1 < 2 has the value 1 1 > 2 has the value 0 The relational operators have lower precedence than the arithmetic operators. For example: i + j < k 1 means (i + j) < (k 1)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Equality Conditions The equality operators are: == equality != inequality e equality operators produce either 1 or 0 as The equality operators produce either 1 or 0 as their result.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 31

P.Lecture - 1.24.08 - Announcements Assignment 1 due...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online