Lauretta J. Fox
Program
3
|
introduces interaction between the programmer and the computer. The results will be printed in a sentence.
|
10 REM FIND THE AREA OF A SQUARE
20 PRINT “HOW LONG IS THE SIDE OF THE SQUARE?”
30 INPUT S
40 IF S = 0 THEN 70
45 LET A = S 2
50 PRINT “THE SIDE OF THE SQUARE IS” S
60 PRINT “THE AREA OF THE SQUARE IS” A
65 GO TO 30
70 END
Result
:
|
How long is the side of the square?
|
|
? (The computer waits for the value to be typed) 49
|
|
The side of the square is 49.
|
|
The area of the square is 2401.
|
|
? (Here the computer waits for the next value.) 32
|
|
The side of the square is 32.
|
|
The area of the square is 1024.
|
|
? (This process repeats until the value O is given for a side, then the program stops.)
|
Explanation of Program 3
:
Line 20
|
asks the programmer to provide the data necessary to solve the problem.
|
Line 30
|
causes the computer to stop and wait for the programmer to type in the data.
|
Line 40
|
tells the computer that the programmer is finished when O is given as the length of a side.
|
Line 45
|
provides the formula to find the area of a square. The arrow pointing upward is used to signify that S is being raised to a power. The numeral 2 is the desired power.
|
Lines 50
|
result in a printout of the words inside the
|
60
|
quotation marks as well as the values of the variables S and A
|
Line 65
|
reroutes the computer back to line 30 for the next value of S. The program continues from line 30 to line 65 over and over until the value O is typed in to stop the program.
|
Program
4
|
provides a method for finding the areas of many squares. It introduces the concept of incrementing a number.
|
____
10 REM FIND THE AREAS OF ALL SQUARES WHOSE SIDES
____
11 REM ARE MULTIPLES OF THREE FROM 9 TO 81
____
19 LET S = 9
____
30 LET A = S 2
____
32 PRINT “S= “ S, “A= “A
____
40 LET S= S + 3
____
41 IF S > 81 THEN 60
____
45 GO T0 30
____
60 END
Result:
|
S = 9
|
A = 81
|
|
S = 12
|
A = 144
|
|
S 15
|
A 225
|
|
S 18
|
A 324
|
|
. . . . . .
|
. . . . . .
|
|
S 75
|
A 5625
|
|
S 78
|
A 6084
|
|
S 81
|
A 6561
|
Explanation of Program
4
Line 40
|
S=S+3 is not an equation. It means to replace S 3 with the number whose value is 3 more than the previous value of S.
|
Line 41
|
tells the computer to stop the program when the value of S becomes greater than 81.
|
Line 45
|
reroutes the computer back to repeat lines 30, 32 and 40 until the value of S is greater than 81.
|