GCF and LCM in BASIC

Introduction

Sometimes I think there are as many ways to find the Greatest Common Factor of two numbers as there are mathematicians in the world. 

Any way you slice it, teaching the computer how to do something for you is the ultimate accomplishment.

Task

Today I am going to give you two broken pieces of code - one for a GCF program and the other for an LCM program. If you get them working correctly, feel free to use them IXL E.7 and E.8

 

Remember the important functions for the BASIC programming language:

HOME - Clears the screen.

INPUT - Asks for input from the user. (ex - INPUT "First Number: "; A)

GOTO - Tells the program to jump to another line number. (ex - GOTO 90)

PRINT - Displays certain information on the screen. (PRINT "The answer is "; A)

IF      THEN - Acts a certain way if the statement is true; moves on if the  

                    statement is false. (ex - IF A<0 THEN A=A+B)

END - Terminates the program.

LET - Sets a value for a variable (ex - LET D=40)

Process

Open http://www.calormen.com/jsbasic/ in another tab. Copy and paste the code for one of the programs into the code box. Replace the blanks with the correct function and test the code to see that it works.

GREATEST COMMON FACTOR - BROKEN

10 ____
20 INPUT "A: "; __
30 _____ "B: "; B
40 IF A=B THEN _____ 80
50 IF A>B _____ A=A-B
60 IF A__B THEN B=B-A
70 GOTO 40
80 PRINT ""
90 _____ "THE GCF IS "; A
100 END

LEAST COMMON MULTIPLE - BROKEN

10 HOME
20 _____ "A: "; A
30 _____ "B: "; B
31 LET C=A
32 LET __=B
40 __ C=D THEN GOTO 80
50 __ C>D THEN D=D+B
60 __ C<D THEN C=C+A
70 GOTO 40
80 PRINT ""
90 PRINT "THE ___ IS "; C
100 ___