biswasrohit20

f# Ex 7

May 20th, 2021 (edited)
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.67 KB | None | 0 0
  1. // Exercise 7 – General
  2. // Leap Year
  3. // Question 1
  4.  
  5. open System
  6.  
  7. let isleap (y:int):bool =
  8.     if y % 400 = 0  then true
  9.     else if y % 4 = 0 && y % 100 > 0 then true
  10.     else false
  11.  
  12.  
  13. printfn "%b" (isleap(2021))
  14.  
  15. Console.ReadKey() |> ignore
  16.  
  17.  
  18.  
  19.  
  20.  
  21. // Question 2
  22. // Days to end Year
  23.  
  24. open System
  25.  
  26. let isleap (y:int):bool =
  27.     if y % 400 = 0  then true
  28.     else if y % 4 = 0 && y % 100 > 0 then true
  29.     else false
  30.  
  31. let daysToEndYear (year:int) : int=
  32.     let mutable days = 365*year
  33.     for i in [1..year] do
  34.         if (isleap(i)) = true then days <- days+1    
  35.     days
  36.    
  37. printfn "%i" (daysToEndYear(1792))
  38.  
  39. Console.ReadKey() |> ignore
Add Comment
Please, Sign In to add comment