Lec_HES1300_2_3

Lec_HES1300_2_3 - HES1300 C Programming Lecture Notes Part...

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

View Full Document Right Arrow Icon
Swinburne University of Technology 1 HES1300 C Programming Lecture Notes – Part 2 © Swinburne University of Technology Algorithms and Programs ± Programming is the activity of communicating algorithms to computers. ± An algorithm is a step by step procedure to perform a task or solve a problem. © Swinburne University of Technology Algorithms and Programs ± Some examples of algorithms: ² A Cooking recipe. ² A musical score. ² A do-it yourself book. © Swinburne University of Technology Algorithms and Programs ± Properties of algorithms: ² Necessary: ² Unambiguous - meaning is clear. ² Deterministic - next step is always unique. ² Finite - always terminates. ² Desirable: simple and general. © Swinburne University of Technology Writing Algorithms ± A process known as STEPWISE REFINEMENT is often used for designing algorithms. ± Begin with a very abstract set of steps. Express each step as a simple English phrase, listing one step per line, eg: ² Step A ² Step B ² Step C © Swinburne University of Technology Writing Algorithms ± Next, refine each step into a sequence, repetition or selection of (sub)steps. ± Start each major step at the left margin. ± Each substep is then indented, eg stepA is refined into stepA1, stepA2, etc.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Swinburne University of Technology 2 © Swinburne University of Technology Writing Algorithms ± The following algorithm describes what to do when you are looking for a snack: look for snack open cupboard. if cookie not in cupboard repeat 5 times take a step towards fridge open fridge. pick up an ice cream. otherwise pick up cookie eat snack. stop. © Swinburne University of Technology Writing a program ± Just as humans read instructions in their own particular preferred language, so do computers. ± A program is an algorithm, expressed in the language of a computer. Unfortunately, the language of a computer (known as machine language) is difficult for humans to understand. ± When computers were first developed, humans had to learn machine language and had to express their algorithm directly in that form. This was a very tedious task. © Swinburne University of Technology Writing a program ± Since that time, tools have been developed which make the process a lot easier, by enabling people to express their algorithm in a programming language. ± A programming language is a language designed specifically to make it easier for people to program computers. © Swinburne University of Technology Functions in The C Programming Language ± The fundamental building block of a C program is the function . A function is analogous to a step in an algorithm. Just as algorithms are described in steps, functions define steps consisting of function calls. ± A function in C is listed by giving its name, followed by a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/29/2010 for the course C++ c taught by Professor Lauren during the Three '10 term at Swinburne.

Page1 / 7

Lec_HES1300_2_3 - HES1300 C Programming Lecture Notes Part...

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

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