Multiplication tables: Difference between revisions
Content added Content deleted
(added ocaml) |
|||
Line 280: | Line 280: | ||
{{trans|C}} |
{{trans|C}} |
||
<lang ocaml>let |
<lang ocaml>let () = |
||
let () = |
|||
let max = 12 in |
let max = 12 in |
||
let fmax = float_of_int max in |
let fmax = float_of_int max in |
||
let dgts = int_of_float ( |
let dgts = int_of_float (ceil (log10 (fmax *. fmax))) in |
||
let fmt = |
let fmt = Printf.printf " %*d" dgts in |
||
let fmt2 = |
let fmt2 = Printf.printf "%*s%c" dgts in |
||
fmt2 "" 'x'; |
|||
for i = 1 to max do |
for i = 1 to max do fmt i done; |
||
print_string "\n\n"; |
print_string "\n\n"; |
||
for j = 1 to max do |
for j = 1 to max do |
||
fmt j; |
|||
for i = 1 to pred j do |
for i = 1 to pred j do fmt2 "" ' '; done; |
||
for i = j to max do |
for i = j to max do fmt (i*j); done; |
||
print_newline() |
print_newline() |
||
done; |
done; |
||
print_newline()</lang> |
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}}== |
=={{header|Perl}}== |