Advertisement
biswasrohit20

f# Ex 8

May 20th, 2021
1,779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.60 KB | None | 0 0
  1. // Exercise 8 – General (Continued from Exercise 7)
  2. // Question 3
  3. // Days to month end
  4.  
  5.  
  6. open System
  7.  
  8.  
  9. let isleap (y:int):bool =
  10.     if y % 400 = 0  then true
  11.     else if y % 4 = 0 && y % 100 > 0 then true
  12.     else false
  13.  
  14.  
  15. let daysToEndYear (year:int) : int=
  16.     let mutable days = 365*year
  17.     for i in [1..year] do
  18.         if (isleap(i)) = true then days <- days+1  
  19.     days
  20.  
  21.  
  22. let daysToEndMonth(m:int,year:int):int =
  23.     let mutable days = daysToEndYear (year-1)
  24.     if m = 1 then days <- days + ((367*m + 5)/12)
  25.     else if m > 1 && (isleap(year)) = true then days <- days + ((367*m + 5)/12 - 1)
  26.     else if m > 1 && (isleap(year)) = false then days <- days + ((367*m + 5)/12 - 2)
  27.     days
  28.    
  29.    
  30. printfn "%i" (daysToEndMonth(9,1792))
  31.  
  32. Console.ReadKey() |> ignore
  33.  
  34.  
  35.  
  36. // Question 4
  37. // Era date
  38.  
  39.  
  40. open System
  41.  
  42. let isleap (y:int):bool =
  43.     if y % 400 = 0  then true
  44.     else if y % 4 = 0 && y % 100 > 0 then true
  45.     else false
  46.  
  47.  
  48.  
  49. let daysToEndYear (year:int) : int=
  50.     let mutable days = 365*year
  51.     for i in [1..year] do
  52.         if (isleap(i)) = true then days <- days+1
  53.    
  54.     days
  55.  
  56.  
  57. let daysToEndMonth(m:int,year:int):int =
  58.     let mutable days = daysToEndYear (year-1)
  59.     if m = 1 then days <- days + ((367*m + 5)/12)
  60.     else if m > 1 && (isleap(year)) = true then days <- days + ((367*m + 5)/12 - 1)
  61.     else if m > 1 && (isleap(year)) = false then days <- days + ((367*m + 5)/12 - 2)
  62.     days
  63.    
  64.  
  65. let eraDay(d:int,m:int,year:int) : int= daysToEndMonth(m-1, year) + d
  66.    
  67.    
  68. printfn "%i" (eraDay(12,3,1999))
  69.  
  70. Console.ReadKey() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement