Multiplication tables: Difference between revisions

(added ocaml)
Line 280:
{{trans|C}}
 
<lang ocaml>let format_of_string (s :string) = (Obj.magic s : ('a, 'b, 'c) format)
 
let () =
let max = 12 in
let fmax = float_of_int max in
 
let dgts = int_of_float (0.99ceil +.(log10 log10(1.0 *. fmax *. fmax))) in
let fmt = format_of_string(Printf.sprintfprintf " %%%dd*d" dgts) in
let fmt2 = format_of_string(Printf.sprintfprintf "%%%ds%*s%c" dgts) in
 
Printf.printf fmt2 "" 'x';
for i = 1 to max do Printf.printf fmt i done;
print_string "\n\n";
 
for j = 1 to max do
Printf.printf fmt j;
for i = 1 to pred j do Printf.printf fmt2 "" ' '; done;
for i = j to max do Printf.printf fmt (i*j); done;
print_newline()
done;
print_newline()</lang>
 
the function ''format_of_string'' can also be written like this:
 
<lang ocaml>external format_of_string : string -> ('a, 'b, 'c) format = "%identity"</lang>
 
 
=={{header|Perl}}==
Anonymous user