Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* Problem 5 *)
- (* numberToName (a)
- TYPE: int -> string
- PRE: int 0-99
- POST: ett heltal representerat av dess bokstaverade motsvarighet
- EXAMPLES: numberToName(1) -> "ett"
- EXAMPLES: numberToName(40) -> "fyrtio"
- *)
- fun numberToName (a):string =
- case a of
- 0 => "noll"
- | 1 => "ett"
- | 2 => "två"
- | 3 => "tre"
- | 4 => "fyra"
- | 5 => "fem"
- | 6 => "sex"
- | 7 => "sju"
- | 8 => "åtta"
- | 9 => "nio"
- | 10 => "tio"
- | 11 => "elva"
- | 12 => "tolv"
- | 13 => "tretton"
- | 14 => "fjorton"
- | 15 => "femton"
- | 16 => "sexton"
- | 17 => "sjutton"
- | 18 => "artton"
- | 19 => "nitton"
- | 20 => "tjugo"
- | 30 => "trettio"
- | 40 => "fyrtio"
- | 80 => "åttio"
- | 90 => "nittio"
- | x => if x > 20 andalso x < 100 then
- case ord(createchar(Int.toString(x)))*10 of
- 10 => "tio"
- | 11 => "elva"
- | 12 => "tolv"
- | 13 => "tretton"
- | 14 => "fjorton"
- | 15 => "femton"
- | 16 => "sexton"
- | 17 => "sjutton"
- | 18 => "artton"
- | 19 => "nitton"
- | 20 => "tjugo"
- | 30 => "trettio"
- | 40 => "fyrtio"
- | 80 => "åttio"
- | 90 => "nittio"
- else
- "noll";
- (50, numberToName(1) = "ett");
- (51, numberToName(40) = "fyrtio");
Add Comment
Please, Sign In to add comment