The following simple programs illustrate QBASIC syntax for simple processes. Using QBASIC enter and run each of the following programs. Try to determine how the output was produced from the program commands.
SCREEN 9
INPUT "Radius"; radius CIRCLE (200, 200), radius, 2 ' 2 is color
green
LINE (100, 100)-(100 + radius, 100 + radius), 3, B ' 3 is blue
CLS
INPUT "Type in an integer number greater than 2 ", N
LPRINT "Your number is "; N A$ = "YES"
FOR Test = 2 TO SQR(N)
IF INT(N / Test) = N / Test THEN A$ = "NO": PRINT "Divisor:";
Test
NEXT Test
PRINT "This is a PRIME number?.. "; A$ _
_______________ ___________________ ______________
2000 and 3001.
RANDOMIZE TIMER
INPUT "How many flips"; Num
PRINT "Number of flips "; Num
Heads = 0
FOR Flip = 1 TO Num
IF RND > .5 THEN Heads = Heads + 1
NEXT Flip
PRINT "Percent of Heads = "; Heads / Num * 100; "%"
How many flips? 10 000
# of Heads = 5060
How many flips? 5060
# of Heads = 2549
How many flips? 2549
# of Heads = 1257
How many flips? 1257
# of Heads = 629
How many flips? 629
# of Heads = 298
How many flips? 298
# of Heads = 143
Trial # | Num Heads |
1 | 10000 |
2 | 5060 |
3 | 2549 |
4 | 1257 |
5 | 629 |
6 | 298 |
7 | 143 |
RANDOMIZE TIMER
SCREEN 12
FOR Picture = 1 TO 50
X = 30 + RND * 550
Y = 30 + RND * 300
Radius = RND * 50
Color1 = RND * 12
Color2 = RND * 12
CIRCLE (X, Y), Radius, Color1
CIRCLE (X, Y), Radius + 1, Color1
PAINT (X, Y), Color2, Color1
NEXT Picture
RANDOMIZE TIMER
SCREEN
FOR Pic = 1 TO 500
X = 30 + RND * 550
Y = 30 + RND * 300
Radius = RND * 100
COLOR1 = RND * 12
COLOR2 = RND * 12
LINE (X, Y)-(X + Radius, Y + Radius), COLOR1, B
LINE (X, Y)-(X + Radius + 1, Y + Radius + 1), COLOR1, B
PAINT (X + 2, Y + 2), COLOR2, COLOR1
NEXT Pic