Program PascalTriangle;
uses crt;
{Give your regards to Yaşar Çilek, a wishful thank is enough}
{////////////////////////////////////////}
{This is where factorial is calculated}
function Factorial(n:longint):longint;
var
j,i:longint;
Begin
j:=1;
for i:= 1 to n do
j:=j*i;
Factorial:=j;
End;
{/////////////////////////////////////}
{//////////////////////////////////////////////////////////}
{This is where magic happens, each number on the table is calculated here,
with a little bit of math info you will recognize it}
function DoCombination(r,d:byte):real;
Begin
DoCombination:=Factorial(r)/(Factorial(d)*Factorial(r-d))
End;
{/////////////////////////////////////////////////////////////////////////////}
{This is the main program}
var
r:byte;
d:byte;
Begin
clrscr;
gotoxy(30,10);
textcolor(black);
textbackground(green);
write('Generating Table Now');
gotoxy(30,12);
write('Please Stand By...');
Delay(5000);
textcolor(black);
Textbackground(green);
clrscr;
For r:= 0 to 12 do {Notice that it is only 12 after 12 it just goes crazy}
Begin {Probably it is because of factorial function,but this is a simple program}
for d:=0 to r do
write(DoCombination(r,d):0:0,' ');
delay(200);
Writeln;
End;
textcolor(black+blink);
writeln('Done');
textcolor(black);
textbackground(green);
gotoxy(25,20);
write('Successfully generated 12 rows!!!');
ReadKey;
End.