program 1
100 REM FIND THE SUM OF THE TWO NUMBERS
200 LET A=9
300 LET B=6
400 LET C=A+B
500 PRINT A,B,C
600 END
Results:
Explanation—program 1
-
Line 100 A “REM” statement is used to make a remark or comment about the program without affecting the program. It doesn’t matter how many “REM” statements are used in a program.
-
Line 200 This “LET” statement assigns the variables values.
-
300
-
Line 400 “LET” tells the computer the formula for the variables.
-
Line 500 “PRINT” tells the computer what to print on the terminal. The commas between the variables tell the computer how to space what is to be printed. A semicolon between the variables puts the printed material closer together.
Line 600 “END” tells the computer that the program is complete.
program 2
10 REM FIND THE PERIMETERS OF RECTANGLES
20 PRINT “TYPE IN TWO NUMBERS SEPARATED BY COMMAS”
30 INPUT A,B
40 IF A=99 THEN 90
50 LET C = 2*A + 2*B
60 PRINT “SIDE”, “SIDE”, “PERIMETER”
70 PRINT A,B,C
80 GO TO 20
90 END
Results:
TYPE IN TWO NUMBERS SEPARATED BY COMMAS
SIDE
|
SIDE
|
PERIMETER
|
5
|
7
|
24
|
Explanation—program 2
-
Line 20 “PRINT” with a message in quotation marks will print the message exactly as it is shown.
-
Line 30 “INPUT” tells the computer that data has to be typed into the terminal before the program will continue.
-
Line 40 “IF” tells the computer if the value for A=99 then go to statement 90 which will stop the program. If A= any other value the program will continue.
-
Line 50 When writing a formula multiplication symbols need to be used, they can’t be assumed. C = 2A + 2B will cause an error statement to appear.
-
Line 60 The commas that separate what is to be printed will allow for neat columns in the printed results. The words in quotation marks will be the headings for each column.
-
Line 80 “GO TO” tells the computer which line to continue the program on. This “GO TO” statement will allow the program to compute perimeters until the programmer is tired and types 99 into the terminal to end the program.