Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.61 KB | None | 0 0
  1. module Program1 =
  2.  
  3.     open System
  4.  
  5.     let read() =
  6.         printf "Introduceti dimensiunea: "
  7.         int (Console.ReadLine())
  8.     let mainP1() =  
  9.         let a = read()
  10.         let b = read()
  11.         let c = read()
  12.         let validare a b c = if (a<b+c) && (b<a+c) && (c<a+b) && (a>0) && (b>0) && (c>0) then "Triunghiul este valid" else "Triunghiul nu este valid"
  13.         let message = validare a b c
  14.         printfn "%s" message
  15.  
  16. // ====================================================================
  17.  
  18. module Program2 =  
  19.    
  20.         let and' a b = a && b
  21.        let or' a b = a || b
  22.         let not' a = not a
  23.        let xor' a b = and' (or' a b) (not'(and' a b))
  24.  
  25.         let printLine f a b =
  26.             printfn "%A\t%A\t%A" a b (f a b)
  27.  
  28.         let printTable f =
  29.             printLine f false false
  30.             printLine f false true
  31.             printLine f true false
  32.             printLine f true true
  33.    
  34.         let mainP2() =
  35.             printTable xor'
  36.  
  37. // ====================================================================
  38.  
  39. module Program3 =  
  40.  
  41.        let rec sqrtRecursive b x =
  42.            if abs((b*b)-x) > 1e-12 then sqrtRecursive (((x/b)+b)/2.0) x
  43.            else b
  44.        
  45.        let sqrt' x =
  46.             if x < 0.0 then nan
  47.             else sqrtRecursive x x
  48.        
  49.         let result = sqrt' 9.0
  50.  
  51.        let mainP3() =
  52.            printfn "%f" result
  53.  
  54. // ====================================================================
  55.  
  56. [<EntryPoint>]
  57. let main argv =  
  58.    Program1.mainP1()
  59.    Program2.mainP2()
  60.    Program3.mainP3()
  61.    0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement