Math Snippets


Why reinvent the wheel? These snippets are freely shared for math educators to use within their Just BASIC programs. If you have a reliable snippet for math functions, please consider sharing.

Table of Contents


  • Basic Math Functions
Finding Least Common Multiple

  • Geometry Functions
How to draw a circle with 2 different functions
Finding the Area of a Rectangle







Basic Math

Basic Math functions include snippets for Addition, Subtraction, Multiplication, Division, Fractions, Decimals, etc.


Finding the Least Common Multiple
Snippet using a Gosub
    n1 = 8
    n2 = 6
Print n1, n2
    Gosub [LCM]
 
Print "LCM = ";LCM
 
End
 
[LCM]
    For i = n1 * n2 to 2 Step -1
        If i Mod n1 = 0 Then
            If i Mod n2 = 0 Then
                LCM = i
            End If
        End If
    Next i
Return
Snippet using a Function
    n1 = 4
    n2 = 6
Print n1, n2
Print "LCM = ";LCM(n1, n2)
 
End
 
Function LCM(n1, n2)
    For i = n1 * n2 to 2 Step -1
        If i Mod n1 = 0 Then
            If i Mod n2 = 0 Then
                LCM = i
            End If
        End If
    Next i
End Function