How to Design Programs: An Introduction to Programming and Computing

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

View Full Document Right Arrow Icon
How to Design Programs: An Introduction to Computing and Programming [Go to first , previous , next page; contents ; index ] Section 2 Numbers, Expressions, Simple Programs In the beginning, people thought of computers as number crunchers. And indeed, computers are very good at working with numbers. Since teachers start their first-graders on computing with numbers, we start with numbers, too. Once we know how computers deal with numbers, we can develop simple programs in no time; we just translate common sense into our programming notation. Still, even developing such simple programs requires discipline, and so we introduce the outline of the most fundamental design recipe and the basic programming guideline at the end of this section. 2.1 Numbers and Arithmetic [../icons/plt.gif] Computing Numbers come in many different flavors: positive and negative integers, fractions (also known as rationals), and reals are the most widely known classes of numbers: 5 -5 2/3 17/3 #i1.4142135623731 The first is an integer, the second one a negative integer, the next two are fractions, and the last one is an inexact representation of a real number. Like a pocket calculator, the simplest of computers, Scheme permits programmers to add, subtract, multiply, and divide numbers: (+ 5 5) (+ -5 5) (+ 5 -5) (- 5 5) (* 3 4) (/ 8 12) The first three ask Scheme to perform additions; the last three demand a subtraction, a multiplication, and a division. All arithmetic expressions are parenthesized and mention the operation first; the numbers follow the operation and are separated by spaces. [../icons/plt.gif] Stepper file:///C|/Documents%20and%20Settings/Linda%20Graue.../How%20to%20Design%20Programs/curriculum-Z-H-5.html (1 of 18) [2/5/2008 4:42:35 PM]
Image of page 1

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

View Full Document Right Arrow Icon