Professional Documents
Culture Documents
Programming
Fundamental
Software
Windows, OS X, Linux
Application programs
End-user applications
Word processor, etc.
Matlab, etc.
A program that:
Examples:
Windows XP/Vista
Linux
http://en.wikipedia.org/wiki/File:Operating_system_placement.svg
Create/Edit
source files
Program Development
(your program!)
Compile
source files
Link
compiled files
Load
executable file
Run
your program!
Test
Repeat process
Correct
Not correct
Structured Programming
Sequence
Selection
IF
IF ELSE
SWITCH
Repetition
WHILE
DO WHILE
FOR
Flowchart constructs
Algorithm
What is an algorithm?
A recipe
A procedure
Definition:
Characteristics of an Algorithm
Well-ordered:
Unambiguous:
Effectively computable:
Pseudocode
Flowcharts - 1
Flowcharts
Name/Meaning
Symbol
Meaning
Control Structures
Control Structures
Example:
Example:
Example:
1. Start
2. Declare variables: ________
3. Repeat while number not equal to -1
3.1. get number
3.2. add to sum
4. Display sum
1. Start
2. Declare variables: num, sum
3. while num not equal to -1, continue doing:
3.1. Display prompt Enter positive number
3.2. Read number from the keyboard
3.3. Display number entered
3.4. add to sum
4. Display sum
Are we there yet?
Example:
1. Start
2. Declare variables: num, sum
3. while num not equal to -1, continue doing:
3.1. Display prompt Enter positive number
3.2. Read number from the keyboard
3.3. Display number entered
3.4. if num less than zero, then
3.4.1 continue
3.5. add to sum
4. Display sum
Are we there now?
Flowchart
Start
1. Start
2. Declare variables: num, sum
3. while num not equal to -1, continue doing:
3.1. Display prompt Enter positive number
3.2. Read number from the keyboard
3.3. Display number entered
3.4. if num less than zero, then
3.4.1 continue
3.5. add to sum
4. Display sum
if num ! = -1
No
Display sum
Yes
Display "Enter
positive integer"
Display num
Stop
if num < 0
No
sum = sum + num
Yes
Structure of a C Program
So does a program in C
Burford Furman
Title
Professor
Dept. of Mech. and Aero. Eng
San Jos State University
San Jose, CA 95192-0087
block
Date
Salutation
Body
Sincerely,
Closing
Jane Student
Signature
C Code
Programmers block
Pre-processor directive
Main function (statements go between { } )
While loop
(repetition structure)
return statement
Programmers Block
Title
Date
Author
Description
Inputs/Outputs
Algorithm
Revision history
main() function
Statements go between
the braces { }
main() ends with the
return keyword and
usually the value zero
If main() runs
successfully, it returns
a value of zero
while (condition)
repeat statements
between { }
Full program