# QuickBASIC

Implementation of programming language BasicQuickBASIC is an IDE and compiler for Basic, developed by Microsoft.

It is somewhat based on GW-BASIC and in turn influenced later Basic implementations: QBasic, FreeBasic, Microsoft Visual Basic etc.

First version of QuickBASIC was released on August 18, 1985. The latest version, 4.5, was released in 1988, though QuickBASIC was included in Microsoft BASIC Professional Development System, and its last version was released in October 1990.

## Examples:

### Hello, World!:

Example for versions QBasic 1.1, QuickBASIC 4.5, bwBASIC 2.50```
PRINT "Hello, World!"
```

### Factorial:

Example for versions QBasic 1.1, QuickBASIC 4.5This example uses recursive factorial definition.

The default data type for calculations is floating point, so program output looks like this:

0! = 1

1! = 1

2! = 2

3! = 6

4! = 24

5! = 120

6! = 720

7! = 5040

8! = 40320

9! = 362880

10! = 3628800

11! = 3.99168Е+07

12! = 4.790016Е+08

13! = 6.227021Е+09

14! = 8.717829Е+10

15! = 1.307674Е+12

16! = 2.092279Е+13

```
DECLARE FUNCTION factorial (n)
FOR i = 0 TO 16:
PRINT STR$(i) + "! =" + STR$(factorial(i))
NEXT i
END
FUNCTION factorial (n)
IF n = 0 THEN
factorial = 1
ELSE
factorial = n * factorial(n - 1)
END IF
END FUNCTION
```

### Fibonacci numbers:

Example for versions QBasic 1.1, QuickBASIC 4.5Numbers which have already been calculated are stored in array F and are retrieved from it to calculate the next ones. To get program output in required format, the numbers in the array are concatenated to form one string with required delimiters. `STR$`

function converts a number to a string.

```
DIM F(16)
F(1) = 1
F(2) = 1
FOR i = 3 TO 16:
F(i) = F(i - 1) + F(i - 2)
NEXT i
DIM S AS STRING
S = ""
FOR i = 1 TO 16:
S = S + STR$(F(i)) + ", "
NEXT i
S = S + "..."
PRINT S
```

### Fibonacci numbers:

Example for versions QBasic 1.1, QuickBASIC 4.5This example uses recursive definition of Fibonacci numbers. Each call of `PRINT`

function prints the arguments to a separate line and adds a space before and after printed number, so program output looks like this:

1 ,

1 ,

2 ,

3 ,

5 ,

8 ,

13 ,

21 ,

34 ,

55 ,

89 ,

144 ,

233 ,

377 ,

610 ,

987 ,

…

```
DECLARE FUNCTION fibonacci (n)
FOR i = 1 TO 16:
PRINT fibonacci(i); ", "
NEXT i
PRINT "..."
FUNCTION fibonacci (n)
IF (n <= 2) THEN
fibonacci = 1
ELSE
fibonacci = fibonacci(n - 1) + fibonacci(n - 2)
END IF
END FUNCTION
```

### Fibonacci numbers:

Example for versions QBasic 1.1, QuickBASIC 4.5Fibonacci numbers are calculated using Binet’s formula. The resulting numbers can differ from actual ones slightly due to calculation imprecision; to remove this effect, we use function `INT`

which truncates fractional part of the number.

```
DECLARE FUNCTION FIBONACCI (n)
DIM S AS STRING
S = ""
FOR i = 1 TO 16:
S = S + STR$(INT(FIBONACCI(i) + .1)) + ","
NEXT i
S = S + "..."
PRINT S
FUNCTION FIBONACCI (n)
p1 = ((1 + SQR(5)) * .5) ^ n
p2 = ((1 - SQR(5)) * .5) ^ n
FIBONACCI = (p1 - p2) / SQR(5)
END FUNCTION
```

### Quadratic equation:

Example for versions QuickBASIC 4.5```
PRINT "A = "
INPUT A
IF (A = 0) THEN
PRINT "Not a quadratic equation."
ELSE
PRINT "B = "
INPUT B
PRINT "C = "
INPUT C
D = B * B - 4 * A * C
IF (D = 0) THEN
PRINT "x = " + STR$(-B / 2! / A)
ELSE
IF (D > 0) THEN
PRINT "x1 = " + STR$((-B + SQR(D)) / 2! / A)
PRINT "x2 = " + STR$((-B - SQR(D)) / 2! / A)
ELSE
PRINT "x1 = (" + STR$(-B / 2! / A) + "," + STR$(SQR(-D) / 2! / A) + ")"
PRINT "x2 = (" + STR$(-B / 2! / A) + "," + STR$(-SQR(-D) / 2! / A) + ")"
END IF
END IF
END IF
```

### Factorial:

Example for versions QBasic 1.1, QuickBASIC 4.5This example uses iterative factorial definition. Arithmetic overflow happens when trying to calculate 13!, but different implementations handle it in different ways: QBasic reports an exception, while QuickBasic just proceeds printing negative values.

```
DIM f AS LONG
f = 1
PRINT " 0 ! ="; f
FOR i = 1 TO 16:
f = f * i:
PRINT i; "! ="; f
NEXT i
END
```

## Comments

]]>blog comments powered by Disqus

]]>