FLORIDA HIGH SCHOOLS COMPUTING COMPETITION '80
BASIC PROGRAM SOLUTIONS
 
 
'1.1
' This program will print terms of the Fibinacci sequence.
'
INPUT "Enter number of terms: "; N
A(1) = 1: A(2) = 1
FOR I = 3 TO N
  A(I) = A(I - 1) + A(I - 2)
NEXT I
FOR I = 1 TO N: PRINT A(I); : NEXT I
PRINT
 
 
'1.2
' This program will flash a symbol on/off every 10 seconds.
'
CLS
FOR I = 1 TO 5
  PRINT "*"
  FOR J = 1 TO 1000: NEXT J
  CLS
  FOR J = 1 TO 10000: NEXT J
NEXT I
 
 
'1.3
' This program will display the perimeter of a rectangle.
'
INPUT "Enter L, W: "; L, W
PRINT L + L + W + W
 
 
'1.4
' This program will convert Celcius to Fahrenheit.
'
INPUT "Enter C: "; C
PRINT (C * 9) / 5 + 32
 
 
'1.5
' This program will determine if input is numeral or not.
'
INPUT "Enter character: "; A$
IF A$ = "0" OR VAL(A$) > 0 THEN PRINT "NUMERAL": END
PRINT "NON-NUMERAL"
 


'1.6
' This program will determine gas mileage.
'
INPUT "Enter D, G: "; D, G
PRINT D / G
 
 
'1.7
' This program will test if a number is divisble by 5.
'
INPUT "Enter number: "; N
IF N MOD 5 = 0 THEN PRINT "YES": END
PRINT "NO"
 
 
'1.8
' This program will print the length of a side of a triangle.
'
INPUT "Enter L, H: "; L, H
PRINT SQR(H * H - L * L)
 
 
'1.9
' This program will move a blob across the screen.
'
CLS
FOR C = 1 TO 79
  LOCATE 5, C: PRINT "*"
  FOR J = 1 TO 100: NEXT J
  LOCATE 5, C: PRINT " "
NEXT C




'2.1
' This program will print the largest number in a sequence.
'
INPUT "Enter number of #s: "; N
L = -999
FOR I = 1 TO N
  INPUT "Enter #: "; X
  IF X > L THEN L = X
NEXT I
PRINT L
 
 
'2.2
' This program will determine what figure is made.
'
INPUT "Enter 4 sides: "; S1, S2, S3, S4
IF S4 = 0 THEN PRINT "TRIANGLE": END
IF S1 = S2 AND S2 = S3 AND S3 = S4 THEN PRINT "SQUARE": END
PRINT "RECTANGLE"
 
 
'2.3
' This program will sum numbers from 1000 to 2000.
'
S = 0
FOR I = 1000 TO 2000
  S = S + I
NEXT I
PRINT S
 
 
'2.4
' This program will reverse a 3 digit number.
'
INPUT "Enter number: "; N$
FOR I = LEN(N$) TO 1 STEP -1
  PRINT MID$(N$, I, 1);
NEXT I
 
 
'2.5
' This program will draw a rectangle on the screen.
'
CLS : SCREEN 1: COLOR 0
LINE (0, 0)-(200, 0): LINE -(200, 100)
LINE -(0, 100): LINE -(0, 0)
LOCATE 23, 1: INPUT A$: SCREEN 0: WIDTH 80
 


'2.6
' This program will print 3 numbers in increasing order.
'
INPUT "Enter 3 numbers: "; A(1), A(2), A(3)
FOR I = 1 TO 2
  FOR J = I + 1 TO 3
    IF A(I) > A(J) THEN SWAP A(I), A(J)
  NEXT J
NEXT I
FOR I = 1 TO 3: PRINT A(I); : NEXT I
PRINT
 
 
'2.7
' This program will determine the mean of a set of numbers.
'
INPUT "Enter number of #s: "; N
FOR I = 1 TO N
  INPUT "Enter #: "; X: S = S + X
NEXT I
PRINT S / N
 
 
'2.8
' This program will determine if a number is even or odd.
'
INPUT "Enter number: "; N
IF N MOD 2 = 0 THEN PRINT "EVEN" ELSE PRINT "ODD"
 
 
'2.9
' This program will determine if a number is prime.
'
INPUT "Enter number: ", N
IF N MOD 2 = 0 THEN PRINT "NO": END
FOR I = 3 TO SQR(N)
  IF N MOD I = 0 THEN PRINT "NO": END
NEXT I
PRINT "YES"
 
 
'2.10
' This program will compute value of change.
'
DATA QUARTERS,25,DIMES,10,NICKELS,5,PENNIES,1
FOR I = 1 TO 4
  READ A$(I), A(I): PRINT "How many "; A$(I);
  INPUT X
  S = S + X * A(I)
NEXT I
PRINT S; "CENTS"
 


'2.11
' This program will count number of e's in sentence.
'
INPUT "Enter sentence: "; A$
FOR I = 1 TO LEN(A$)
  IF MID$(A$, I, 1) = "E" THEN E = E + 1
NEXT I
PRINT E




'3.1
' This program allows user to answer multiplication facts.
'
RANDOMIZE TIMER
X = INT(RND(3) * 13): Y = INT(RND(3) * 13)
PRINT X; "X"; Y; " = ";
INPUT N
IF X * Y = N THEN PRINT "RIGHT" ELSE PRINT "WRONG"
 
 
'3.2
' This program will randomize the digits 0..9.
'
RANDOMIZE TIMER
FOR I = 0 TO 9: A(I) = I: NEXT I
FOR I = 0 TO 9
  X = INT(RND(3) * 10)
  Y = A(I): A(I) = A(X): A(X) = Y
NEXT I
FOR I = 0 TO 9: PRINT A(I); : NEXT I: PRINT
 
 
'3.3
' This program will round a number to nearest ten.
'
INPUT "Enter number: "; N
PRINT INT((N + 5) / 10) * 10
 
 
'3.4
' This program will change a number from base 10 to 4.
'
INPUT "Enter number: "; N
J = INT(LOG(N) / LOG(4))
FOR I = J TO 0 STEP -1
  X = INT(N / 4 ^ I): PRINT USING "#"; X;
  N = N - X * 4 ^ I
NEXT I
 
 
'3.5
' This program will change a number from base 3 to 10.
'
INPUT "Enter number: "; N$:
L = LEN(N$)
FOR I = L TO 1 STEP -1
  X = VAL(MID$(N$, I, 1))
  S = S + X * 3 ^ (L - I)
NEXT I
PRINT S
 


'3.6
' This program will change a decimal to a fraction.
'
INPUT "Enter decimal: "; N$
INPUT "R or T: "; A$
L = LEN(N$) - 1
N = VAL(RIGHT$(N$, L))
D = INT(10 ^ L + .1)
IF A$ = "R" THEN D = D - INT(D / 10)
FOR I = N TO 1 STEP -1
  IF N MOD I = 0 AND D MOD I = 0 THEN
    PRINT N / I; "/"; D / I: END
  END IF
NEXT I
 
 
'3.7
' This program will represent an amount of money.
'
DATA HALF,50,QUARTER,25,DIMES,10,NICKELS,5,PENNIES,1
INPUT "Enter cents: "; C
FOR I = 1 TO 5
  READ A$, A
  X = INT(C / A): PRINT X; A$
  C = C - X * A
NEXT I
 
 
'3.8
' This program will allow user to guess a generated #.
'
RANDOMIZE TIMER
X = INT(RND(3) * 10) + 1
WHILE X <> G
  INPUT "Enter guess: "; G
  IF G = X THEN PRINT "RIGHT ON": END
  IF G > X THEN PRINT "TOO HIGH" ELSE PRINT "TOO LOW"
WEND
 
 
'3.9
' This program will find fvalues for a,b,c,d.
'
FOR A = 1 TO 9
  FOR B = 0 TO 9
    FOR C = 0 TO 9
      FOR D = 0 TO 9
        N = A * 1000 + B * 100 + C * 10 + D
        M = INT(A ^ B * C ^ D + .1)
        IF N = M THEN
          PRINT "A="; A; " B="; B; " C="; C; " D="; D: END
        END IF
NEXT D, C, B, A


'3.10
' This program will print day of week for a date.
'
DATA 31,29,31,30,31,30,31,31,30,31,30,31
INPUT "Enter month, day: "; M, D
IF M > 1 THEN
  FOR I = 1 TO M - 1
    READ A: S = S + A
  NEXT I
END IF
S = S + D
X = S - INT(S / 7) * 7
A$ = "MONTUEWEDTHUFRISATSUN"
PRINT MID$(A$, X * 3 + 1, 3)
 
 
'3.11
' This program will simulate an "etch-a-sketch".
'
CLS : ROW = 12: COL = 40
WHILE A$ <> CHR$(27)
  LOCATE ROW, COL: PRINT "*": A$ = ""
  WHILE A$ = "": A$ = INKEY$: WEND
  IF A$ = "I" THEN ROW = ROW - 1
  IF A$ = "M" THEN ROW = ROW + 1
  IF A$ = "J" THEN COL = COL - 1
  IF A$ = "K" THEN COL = COL + 1
WEND
 
 
'3.12
' This program will determine if a word is a palindrome.
'
INPUT "Enter word: "; A$: L = LEN(A$)
FOR I = 1 TO L
  L$ = MID$(A$, I, 1)
  R$ = MID$(A$, L - I + 1, 1)
  IF L$ <> R$ THEN PRINT "NOT "; : I = L
NEXT I
PRINT "PALINDROME"