cs31 lecture 2

There is a single output there may not be any output

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: algorithm Often there is a single output There may not be any output, and/or the output may be an input • Example: input: x, output: x Use a variable name for the output, and a short description 6 Some definitions for writing algorithms x Third section: the algorithm Third the List of instructions to be performed Number the lines, starting at 1 Instructions are executed in order (starts at 1) Plain English is acceptable, but be concise Better: use only a verb (action) to be performed Accepted: use arithmetic operators Usually, name the algorithm (eg, MPG) 7 Some definitions for writing algorithms x Third section: the algorithm Third the An instruction can be using: • A verb (action), which may x x x Be applied on some variable Lead to produce a new variable Example: Example: • Print “foo” • Read character n from keyboard • A keyword: a specific word that describes a standard action x x x return xxx: specify the variable xxx is produced as an output. This instruction exits the algorithm instruction xxx := yyy assigns the content of the variable yyy to the variable xxx xxx := Control structures (if/then...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online