Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.32 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.org
  2. // See the 'F# Tutorial' project for more help.
  3.  
  4. open System;
  5.  
  6. //zad 6
  7. let rec wczytaj n =
  8.      let w:int32 = System.Convert.ToInt32(System.Console.ReadLine());
  9.      if w = 0 then n else wczytaj (w::n)
  10.  
  11. let rec sum n s (l : int List) =
  12.     if n<l.Length then sum (n+1) (s+l.Item(n)) l
  13.     else s;
  14.  
  15. let rec geom n s (l : int List) =
  16.     if n < l.Length then geom (n+1) (s*l.Item(n)) l
  17.     else System.Math.Pow((float)s,(1.0/(float)n));
  18. let zad6 _ =
  19.     let w = wczytaj []
  20.     (sum 0 0 w,geom 0 1 w);
  21.  
  22.  
  23. //zad 7
  24. //funkcja pomocnicza  s
  25. let rec drawLine (s:string) i m n =
  26.     if i >= (m + n) then s elif i < m then drawLine (s+" ") (i+1) m n
  27.     else drawLine (s+"*") (i+1) m n;
  28.  
  29. //a
  30. let rec draw7a s i n =
  31.     if i <= n then draw7a (s+"\n"+(drawLine "" 0 0 i)) (i+1) n else s;
  32.        
  33.  
  34. //zad 8
  35.  
  36. let rec getDividers n i =
  37.     if n=i  then [n] elif (n%i) = 0 then i::(getDividers n (i+1))
  38.     else (getDividers n (i+1))
  39.    
  40.  
  41. //zad 10
  42. let rec zad10 k =
  43.     if (k%4-1) = 0 then true elif (k%4-3) = 0 then false else zad10 (k/2);
  44.  
  45.  
  46.  
  47. [<EntryPoint>]
  48. let main argv =
  49.  
  50.  
  51.     let zad8 = getDividers 12 2;
  52.    
  53.     printfn "%A" (zad10 5);
  54.  
  55.  
  56.     printfn "%A " (List.sort [5;2;1;-3;3]);
  57.  
  58.  
  59.  
  60.     printfn "%A  " argv
  61.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement