{ -- FLORIDA HIGH SCHOOLS COMPUTING COMPETITION '80 } { -- PASCAL PROGRAM SOLUTIONS } {1.1} program One1T80; { -- This program will print terms of the Fibinacci sequence. } var N, I: Integer; A: Array[1..99] of LongInt; begin Write ('Enter number of terms: '); Readln (N); A[1] := 1; A[2] := 1; for I := 3 to N do A[I] := A[I-1] + A[I-2]; for I := 1 to N do Write (A[I], ' '); Writeln; end. {1.2} program One2T80; { -- This program will flash a symbol on/off every 10 seconds. } uses Crt; var I: Byte; begin ClrScr; for I := 1 to 5 do begin Write ('*'); delay (500); ClrScr; delay (6000); end; end. {1.3} program One3T80; { -- This program will display the perimeter of a rectangle. } var L, W: Integer; begin Write ('Enter L, W: '); Readln (L, W); Writeln (L + L + W + W); end. {1.4} program One4T80; { -- This program will convert Celcius to Fahrenheit. } var C: Integer; begin Write ('Enter C: '); Readln (C); Writeln ( (C * 9) / 5 + 32 :2:0); end. {1.5} program One5T80; { -- This program will determine if input is numeral or not. } var Ch: Char; begin Write ('Enter character: '); Readln (Ch); if Ch in ['0' .. '9'] then Writeln ('NUMERAL') else Writeln ('NON-NUMERAL'); end. {1.6} program One6T80; { -- This program will determine gas mileage. } var D, G: Integer; begin Write ('Enter D, G: '); Readln (D, G); Writeln (D div G); end. {1.7} program One7T80; { -- This program will test if a number is divisible by 5. } var N: Integer; begin Write ('Enter number: '); Readln (N); if N mod 5 = 0 then Writeln ('YES') else Writeln ('NO'); end. {1.8} program One8T80; { -- This program will print the length of a side of a triangle. } var L, H: Integer; begin Write ('Enter L, H: '); Readln (L, H); Writeln (Sqrt(H*H - L*L) :1:0); end. {1.9} program One9T80; { -- This program will move a blob across the screen. } uses Crt; var C: Integer; begin ClrScr; for C := 1 to 79 do begin GotoXY (C,2); Write ('*'); Delay (10); GotoXY (C,2); Write (' '); end; end. {2.1} program Two1T80; { -- This program will print the largest number in a sequence. } var N, I, X, Max: Integer; begin Write ('Enter number of #s: '); Readln (N); Max := -999; for I := 1 to N do begin Write ('Enter #: '); Readln (X); if X > Max then Max := X; end; Writeln (Max); end. {2.2} program Two2T80; { -- This program will determine what figure is made. } var S1, S2, S3, S4: Integer; begin Write ('Enter 4 sides: '); Readln (S1, S2, S3, S4); if S4 = 0 then Writeln ('TRIANGLE') else if (S1 = S2) and (S2 = S3) and (S3 = S4) then Writeln ('SQUARE') else Writeln ('RECTANGLE'); end. {2.3} program Two3T80; { -- This program will sum numbers from 1000 to 2000. } var I: Integer; S: LongInt; begin S := 0; for I := 1000 to 2000 do S := S + I; Writeln (S); end. {2.4} program Two4T80; { -- This program will reverse a 3 digit number. } var N: String[3]; I: Byte; begin Write ('Enter number: '); Readln (N); for I := 3 downto 1 do Write (Copy(N, I, 1)); Writeln; end. {2.5} program Two5T80; { -- This program will draw a rectangle on the screen. } uses Crt; var I: Byte; begin ClrScr; for I := 1 to 20 do Write ('*'); Writeln; for I := 1 to 5 do Writeln ('*', ' ':18, '*'); for I := 1 to 20 do Write ('*'); end. {2.6} program Two6T80; { -- This program will print 3 numbers in increasing order. } var I, J, X: Integer; A: Array [1..3] of Integer; begin Write ('Enter 3 number: '); Readln (A[1], A[2], A[3]); for I := 1 to 2 do for J := I+1 to 3 do if A[I] > A[J] then begin X := A[I]; A[I] := A[J]; A[J] := X; end; for I := 1 to 3 do Write (A[I], ' '); Writeln; end. {2.7} program Two7T80; { -- This program will determine mean of set of numbers. } var N, I, X, S: Integer; begin Write ('Enter number of #s: '); Readln (N); S := 0; for I := 1 to N do begin Write ('Enter #: '); Readln (X); S := S + X; end; Writeln (S / N :3:1); end. {2.8} program Two8T80; { -- This program will determine if a number is even or odd. } var N: Integer; begin Write ('Enter number: '); Readln (N); if N mod 2 = 0 then Writeln ('EVEN') else Writeln ('ODD'); end. {2.9} program Two9T80; { -- This program will determine if a number is prime. } var N, I, Sq: Integer; begin Write ('Enter number: '); Readln (N); Sq := Trunc( Sqrt(N) ); if N mod 2 = 0 then begin Writeln ('NO'); Exit; end else for I := 3 to Sq do if N mod I = 0 then begin Writeln ('NO'); Exit; end; Writeln ('YES'); end. {2.10} program Two10T80; { -- This program will compute value of change. } const Coin: Array [1..4] of String[8] = ('QUARTERS', 'DIMES', 'NICKELS', 'PENNIES'); Amount: Array[1..4] of Integer = (25, 10, 5, 1); var I, X, S: Integer; begin S := 0; for I := 1 to 4 do begin Write ('How many ', Coin[I], '? '); Readln (X); S := S + Amount[I] * X; end; Writeln (S, ' CENTS'); end. {2.11} program Two11T80; { -- This program will count number of e's in sentence. } var I, E: Byte; Sent: String[80]; begin Write ('Enter sentence: '); Readln (Sent); E := 0; for I := 1 to Length(Sent) do if Copy(Sent, I, 1) = 'E' then Inc(E); Writeln (E); end. {3.1} program Thr1T80; { -- This program allows user to answer multiplication facts. } var X, Y, N: Integer; begin Randomize; X := Random(13); Y := Random(13); Write (X, ' X ', Y, ' = '); Readln (N); if X * Y = N then Writeln ('RIGHT') else Writeln ('WRONG'); end. {3.2} program Thr2T80; { -- This program will randomize the digits 0..9. } var I, X, Y: Byte; A: Array [0..9] of Byte; begin Randomize; for I := 0 to 9 do A[I] := I; for I := 0 to 9 do begin X := Random(10); Y := A[I]; A[I] := A[X]; A[X] := Y; end; for I := 0 to 9 do Write (A[I], ' '); Writeln; end. {3.3} program Thr3T80; { -- This program will round a number to nearest ten. } var N: Integer; begin Write ('Enter number: '); Readln (N); Writeln (Trunc((N+5)/10) * 10); end. {3.4} program Thr4T80; { -- This program will change a number from base 10 to 4. } var N, I, J, X, Pow: Integer; begin Write ('Enter number: '); Readln (N); J := Trunc(Ln(N) / Ln(4)); Pow := 1; for I := 0 to J do Pow := Pow * 4; for I := J downto 0 do begin Pow := Pow div 4; X := Trunc(N / Pow); Write (X); N := N - X * Pow; end; Writeln; end. {3.5} program Thr5T80; { -- This program will change a number from base 3 to 10. } var N: String[7]; I, L, S, X, Code, Pow: Integer; begin Write ('Enter number: '); Readln (N); L := Length(N); Pow := 1; S := 0; for I := L downto 1 do begin Val(Copy(N, I, 1), X, Code); S := S + X * Pow; Pow := Pow * 3; end; Writeln (S); end. {3.6} program Thr6T80; { -- This program will change a decimal to a fraction. } var A: Char; Num: String[5]; I, L, N, D, Code: Integer; begin Write ('Enter decimal: '); Readln (Num); Write ('R or T: '); Readln (A); L := Length(Num) - 1; Val (Copy(Num, 2, L), N, Code); D := 1; for I := 1 to L do D := D * 10; if A = 'R' then D := D - D div 10; I := N; while (N mod I <> 0) or (D mod I <> 0) do Dec(I); Writeln (N div I, '/', D div I); end. {3.7} program Thr7T80; { -- This program will represent and amount of money. } const Coin: Array [1..5] of String[8] = ('HALF', 'QUARTER', 'DIMES', 'NICKELS', 'PENNIES'); Amount: Array [1..5] of Integer = (50, 25, 10, 5, 1); var C, X, I: Integer; begin Write ('Enter cents: '); Readln (C); for I := 1 to 5 do begin X := C div Amount[I]; Writeln (X, ' ', Coin[I]); C := C - X * Amount[I]; end; end. {3.8} program Thr8T80; { -- This program will allow user to guess a generated #. } var X, G: Byte; begin Randomize; X := Random(10) + 1; G := 0; while X <> G do begin Write ('Enter guess: '); Readln (G); if G > X then Writeln ('TOO HIGH'); if G < X then Writeln ('TOO LOW'); end; Writeln ('RIGHT ON'); end. {3.9} program Thr9T80; { -- This program will find values for a,b,c,d. } var A, B, C, D, N, M, I, APow, CPow: Integer; begin for A := 1 to 9 do for B := 0 to 9 do for C := 0 to 9 do for D := 0 to 9 do begin N := A*1000 + B*100 + C*10 + D; APow := 1; for I := 1 to B do APow := APow * A; CPow := 1; for I := 1 to D do CPow := CPow * C; M := APow * CPow; if N = M then begin Writeln ('A=', A, ' B=', B, ' C=', C, ' D=', D); exit; end; end; end. {3.10} program Thr10T80; { -- This program will print day of week for a date. } const Days: Array[1..12] of Integer = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var M, D, I, S, X: Integer; Name: String[21]; begin Name := 'MONTUEWEDTHUFRISATSUN'; Write ('Enter month, day: '); Readln (M, D); S := 0; for I := 1 to M-1 do S := S + Days[I]; S := S + D; X := S mod 7; Writeln (Copy(Name, X*3+1, 3)); end. {3.11} program Thr11T80; { -- This program will simulate an "etch-a-sketch". } uses Crt; var Row, Col: Byte; A: Char; begin ClrScr; Row := 12; Col := 40; repeat GotoXY (Col, Row); Write ('*'); A := Readkey; case A of 'I': Dec(Row); 'M': Inc(Row); 'J': Dec(Col); 'K': Inc(Col); end; until A = Char(27); end. {3.12} program Thr12T80; { -- This program will determine if a word is a palindrome. } var A: String[12]; L, R: String[1]; I, Len: Byte; begin Write ('Enter word: '); Readln (A); Len := Length(A); I := 1; repeat L := Copy (A, I, 1); R := Copy (A, Len-I+1, 1); if L <> R then Write ('NOT '); Inc(I); until (I = Len) or (L <> R); Writeln ('PALINDROME'); end.