Friday, September 5, 2025

Times tables Pascal code.

procedure TimTabP;
var
iocode:integer;
ch:char;
a,b,k,ans:integer;
tt:array[1..12] of integer;
begin
repeat
clrscr;
repeat
write('Enter the times table you want printed. ');
{$I-}
readln(a);
{$I+}
iocode:=ioresult;
until (iocode=0) and (a>0) and (a<13);
writeln;
randomize;
for k:=1 to 12 do
tt[k]:=0;

tt[1]:=random(12)+1;
repeat
tt[2]:=random(12)+1
until (tt[2]<>tt[1]);
repeat
tt[3]:=random(12)+1
until (tt[3]<>tt[1]) and (tt[3]<>tt[2]);
repeat
tt[4]:=random(12)+1
until (tt[4]<>tt[1]) and (tt[4]<>tt[2]) and (tt[4]<>tt[3]);
repeat
tt[5]:=random(12)+1
until (tt[5]<>tt[1]) and (tt[5]<>tt[2]) and (tt[5]<>tt[3]) and (tt[5]<>tt[4]);
repeat
tt[6]:=random(12)+1
until (tt[6]<>tt[1]) and (tt[6]<>tt[2]) and (tt[6]<>tt[3]) and (tt[6]<>tt[4])
and (tt[6]<>tt[5]);
repeat
tt[7]:=random(12)+1
until (tt[7]<>tt[1]) and (tt[7]<>tt[2]) and (tt[7]<>tt[3]) and (tt[7]<>tt[4])
and (tt[7]<>tt[5]) and (tt[7]<>tt[6]);
repeat
tt[8]:=random(12)+1
until (tt[8]<>tt[1]) and (tt[8]<>tt[2]) and (tt[8]<>tt[3]) and (tt[8]<>tt[4])
and (tt[8]<>tt[5]) and (tt[8]<>tt[6]) and (tt[8]<>tt[7]);
repeat
tt[9]:=random(12)+1
until (tt[9]<>tt[1]) and (tt[9]<>tt[2]) and (tt[9]<>tt[3]) and (tt[9]<>tt[4])
and (tt[9]<>tt[5]) and (tt[9]<>tt[6]) and (tt[9]<>tt[7]) and (tt[9]<>tt[8]);
repeat
tt[10]:=random(12)+1
until (tt[10]<>tt[1]) and (tt[10]<>tt[2]) and (tt[10]<>tt[3]) and (tt[10]<>tt[4])
and (tt[10]<>tt[5]) and (tt[10]<>tt[6]) and (tt[10]<>tt[7]) and (tt[10]<>tt[8])
and (tt[10]<>tt[9]);
repeat
tt[11]:=random(12)+1
until (tt[11]<>tt[1]) and (tt[11]<>tt[2]) and (tt[11]<>tt[3]) and (tt[11]<>tt[4])
and (tt[11]<>tt[5]) and (tt[11]<>tt[6]) and (tt[11]<>tt[7]) and (tt[11]<>tt[8])
and (tt[11]<>tt[9]) and (tt[11]<>tt[10]);
repeat
tt[12]:=random(12)+1
until (tt[12]<>tt[1]) and (tt[12]<>tt[2]) and (tt[12]<>tt[3]) and (tt[12]<>tt[4])
and (tt[12]<>tt[5]) and (tt[12]<>tt[6]) and (tt[12]<>tt[7]) and (tt[12]<>tt[8])
and (tt[12]<>tt[9]) and (tt[12]<>tt[10]) and (tt[12]<>tt[11]);

for k:=1 to 12 do
writeln(' ',a,' times ',tt[k],' = ',a*tt[k],' ');
writeln('');
write('Another? Y/N');
repeat
ch:=readkey
until (ch in ['Y','y','N','n']);
until (ch in ['N','n']);
end;


No comments:

Post a Comment