lecture06-feb2 - 2/2/09 EE312 - Lecture 6 Announcements...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
2/2/09 1 EE312 - Lecture 6 Announcements • Assignment 2 out tomorrow – Focus on numerics • Topics for today will address: – Algorithm formation example – Finish program control statements (Ch. 6) • Repetition / iteration while Statement The while statement has the form while ( condition ) statement The body of a while statement is executed repeatedly as long as the condition is true (has a nonzero value). The condition is tested before each execution of the statement (or group). Example: int i = 10; /* count down from 10 */ while (i > 0) { printf ("T minus %d and counting\n", i); i--; } Using a nonzero constant as the controlling condition creates an infinite loop: while (1) { ... } condition T F Summing a Series of Numbers I want to be able to sum up a series of integer values that are entered by the user. I don’t know how many. How do I do that? To begin design, represent the program as a closed, black-box system. Identify the inputs and outputs before you begin to describe and outline (plan) the steps inside the process box (IPO). Process Inputs Outputs Series of numbers Sentinel* Sum High Level Algorithm Input a value start stop Output the Total sum Is it the Sentinel? Y N Add the value into The running sum Initialize sum to 0 1. Initialize sum to 0 2. Repeat the following until the sentinel is read: a) Input a value b) Add it to the sum 3. Output the sum 4. Stop Summing a Series of Numbers /* sum up a series of integers entered by the user */ #include <stdio.h> int main(void)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

lecture06-feb2 - 2/2/09 EE312 - Lecture 6 Announcements...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online