Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Exercise 8 – General (Continued from Exercise 7)
- // Question 3
- // Days to month end
- open System
- let isleap (y:int):bool =
- if y % 400 = 0 then true
- else if y % 4 = 0 && y % 100 > 0 then true
- else false
- let daysToEndYear (year:int) : int=
- let mutable days = 365*year
- for i in [1..year] do
- if (isleap(i)) = true then days <- days+1
- days
- let daysToEndMonth(m:int,year:int):int =
- let mutable days = daysToEndYear (year-1)
- if m = 1 then days <- days + ((367*m + 5)/12)
- else if m > 1 && (isleap(year)) = true then days <- days + ((367*m + 5)/12 - 1)
- else if m > 1 && (isleap(year)) = false then days <- days + ((367*m + 5)/12 - 2)
- days
- printfn "%i" (daysToEndMonth(9,1792))
- Console.ReadKey() |> ignore
- // Question 4
- // Era date
- open System
- let isleap (y:int):bool =
- if y % 400 = 0 then true
- else if y % 4 = 0 && y % 100 > 0 then true
- else false
- let daysToEndYear (year:int) : int=
- let mutable days = 365*year
- for i in [1..year] do
- if (isleap(i)) = true then days <- days+1
- days
- let daysToEndMonth(m:int,year:int):int =
- let mutable days = daysToEndYear (year-1)
- if m = 1 then days <- days + ((367*m + 5)/12)
- else if m > 1 && (isleap(year)) = true then days <- days + ((367*m + 5)/12 - 1)
- else if m > 1 && (isleap(year)) = false then days <- days + ((367*m + 5)/12 - 2)
- days
- let eraDay(d:int,m:int,year:int) : int= daysToEndMonth(m-1, year) + d
- printfn "%i" (eraDay(12,3,1999))
- Console.ReadKey() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement