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.
Numbers and Arithmetic
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 |
(+ 5 5) (+ -5 5) (+ 5 -5) (- 5 5) (* 3 4) (/ 8 12) |
As in arithmetic or algebra, we can nest expressions:
(* (+ 2 2) (/ (* (+ 3 5) (/ 30 10)) 2))
(* (+ 2 2) (/ (* (+ 3 5) (/ 30 10)) 2)) = (* 4 (/ (* 8 3) 2)) = (* 4 (/ 24 2)) = (* 4 12) = 48
(operation A ... B)
A ... B
are numbers, the expression can be evaluated; otherwise, A ... B
are evaluated first. Contrast this with
No comments:
Post a Comment
This is Good Computer Information Blog.they will give
best information about computer.