lcm 6 7.2

Oct. 25th, 2011 12:35 pm
[personal profile] gdsfh
Исходный вопрос: [personal profile] nicka_startcev: Какое наименьшее общее кратное у 6 и 7.2 ?
Реализация на C++, обсуждение double: [profile] udpn: Дробная арифметика
Реализация на OCaml, чисто для разминки/отвлечения:

open Cd_All;
open Num;
open Num_as_int;

value t = tnum
;

value rec gcd x y =
  if t#eq y zero
  then x
  else gcd y (mod_num x y)
;

value lcm x y = x * y / (gcd x y)
;

value main () =
  let (a, b) = Tuple2.monomap num_of_string ("6", "72/10") in
  Printf.printf "(lcm %s %s) = %s\n%!"
    (t#show a)
    (t#show b)
    (t#show & lcm a b)
;

value () = main ()
;


$ ./main.byte
(lcm 6 36/5) = 36


Репка тут.
From:
Anonymous( )Anonymous This account has disabled anonymous posting.
OpenID( )OpenID You can comment on this post while signed in with an account from many other sites, once you have confirmed your email address. Sign in using OpenID.
User
Account name:
Password:
If you don't have an account you can create one now.
Subject:
HTML doesn't work in the subject.

Message:

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org


 
Notice: This account is set to log the IP addresses of people who comment anonymously.
Links will be displayed as unclickable URLs to help prevent spam.

Profile

gdsfh

August 2013

S M T W T F S
    123
45678910
111213 14151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 23rd, 2017 02:37 pm
Powered by Dreamwidth Studios