with Ada.Text_IO; use Ada.Text_IO;
with HTML;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package body Mathematics is
function Factorial (Value : Integer) return Integer is
Return_Value : Integer := 1;
Factor : Integer := Value;
begin
if Value = 1 or Value = 0 then
return 1;
else
loop
Return_Value := Return_Value * Factor;
Factor := Factor - 1;
exit when Factor = 0;
end loop;
return Return_Value;
end if;
end Factorial;
function N_over_K (n : Integer; k : Integer) return Integer is
top : Integer := 1;
begin
if k > n then
return 0;
end if;
if k = 0 or n = k then
return 1;
else
for j in 1 .. k loop
top := top * (n + 1 - j);
end loop;
return (top / Factorial (k));
end if;
end N_over_K;
procedure Create_Pascal_Triangle (Height : Integer := 12; File_Name : String := "pascal_triangle.html") is
Out_File : File_Type;
HTML_Contens : Unbounded_String := Null_Unbounded_String;
Lines : Unbounded_String := Null_Unbounded_String;
Item_List : Unbounded_String := Null_Unbounded_String;
begin
Put_Line ("begin Create_Pascal_Triangle.");
Create (File => Out_File, Name => File_Name);
HTML_Contens := HTML.Table (Lines);
Put_Line (Out_File, To_String(HTML.HTML_Document (Body_Contens => HTML_Contens)));
Put_Line ("end Create_Pascal_Triangle.");
end Create_Pascal_Triangle;
procedure Create_Factorial_Table (Height : Integer := 12; File_Name : String := "factorial_table.html") is
Out_File : File_Type;
HTML_Contens : Unbounded_String := Null_Unbounded_String;
Lines : Unbounded_String := Null_Unbounded_String;
Item_List : Unbounded_String := Null_Unbounded_String;
begin
Put_Line ("begin Create_Create_Factorial_Table.");
Create (File => Out_File, Name => File_Name);
Item_List := HTML.Item ("n") & HTML.Item ("n!");
Lines := Lines & HTML.Line(Item_List);
for n in 0..12
loop
Item_List := HTML.Item ( integer'image(n)) & HTML.Item ( integer'image(Factorial(n)));
Lines := Lines & HTML.Line(Item_List);
end loop;
HTML_Contens := HTML.Table (Lines);
Put_Line (Out_File, To_String(HTML.HTML_Document (Body_Contens => HTML_Contens)));
Put_Line ("end Create_Create_Factorial_Table.");
end Create_Factorial_Table;
end Mathematics;