Advertisement
ed195cm

Untitled

Nov 3rd, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. -module(lab01).
  2.  
  3. -compile(export_all).
  4.  
  5. fibTerm(N) ->
  6. SQRT5 = math:sqrt(5),
  7. E1 = math:pow((1 + SQRT5), N),
  8. E2 = math:pow((1 - SQRT5), N),
  9. E3 = math:pow(2, N) * SQRT5,
  10. E4 = (E1 - E2)/E3,
  11. ANS = trunc(E4),
  12.  
  13. io:format("After fibTerm ~w~n", [ANS]).
  14.  
  15. isSame(N1, N2) ->
  16. if
  17. N1 =:= N2 -> true;
  18. true -> false
  19. end.
  20.  
  21. mySign(N3) ->
  22. io:format("Entered Number is ~w, ", [N3]),
  23. if
  24. N3 > 0 -> positive;
  25. N3 < 0 -> negative;
  26. true -> zero
  27. end.
  28.  
  29. smallest(N4, N5, N6) ->
  30. if
  31. (N4 < N5) and (N4 < N6) -> N4;
  32. (N5 < N4) and (N5 < N6) -> N5;
  33. true -> N6
  34. end.
  35.  
  36. fruitType(N7) ->
  37. case N7 of
  38. 1 -> berry;
  39. 2 -> melon;
  40. 3 -> citrus;
  41. 4 -> tropical;
  42. 5 -> pomes;
  43. 6 -> drupes;
  44. _ -> no_match
  45. end.
  46.  
  47. fruitType2(1) -> berry;
  48. fruitType2(2) -> melon;
  49. fruitType2(3) -> citrus;
  50. fruitType2(4) -> tropical;
  51. fruitType2(5) -> pomes;
  52. fruitType2(6) -> drupes;
  53. fruitType2(_) -> no_match.
  54.  
  55. isPrime(2) -> true;
  56. isPrime(N8) when N8 < 2 -> false;
  57. isPrime(N8) when N8 > 2 -> isPrime(N8, 2).
  58. isPrime(N8, D) when (N8 rem D) == 0 -> false;
  59. isPrime(N8, D) when (D*D) > N8 -> true;
  60. isPrime(N8, D) when ((N8 rem 2) == 1) and ((D*D) =< N8) -> isPrime(N8, D+1).
  61.  
  62. mySum(0) -> 0;
  63. mySum(1) -> 1;
  64. mySum(N9) when N9 > 1 -> N9 + mySum(N9 - 1).
  65.  
  66. mySeries(N10, N11, N12) ->
  67. N10 * math:pow(N11, N12 - 1).
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement