Advertisement
Guest User

Untitled

a guest
Jun 6th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Exercício 1
  2. ex1 :: Float -> Float -> Float -> (Float,Float)
  3. ex1 a b c
  4.   | b*b-4*a*c < 0 = error "delta negativo"
  5.   | otherwise = (x1,x2)
  6.   where
  7.     x1 = (-b + sqrt(b*b-(4*a*c)))/(2*a)
  8.     x2 = (-b - sqrt(b*b-(4*a*c)))/(2*a)
  9.  
  10. --Exercício 2
  11. ex2 :: Float -> Float -> Float -> Integer
  12. ex2 a b c
  13.   | ((a > media) && (b <= media) && (c <= media)) = 1
  14.   | ((b > media) && (a <= media) && (c <= media)) = 1
  15.   | ((c > media) && (a <= media) && (b <= media)) = 1
  16.   | ((a > media) && (b > media) && (c <= media))||((a > media) && (b <= media) && (c > media))||((a <= media) && (b > media) && (c > media)) = 2
  17.   | otherwise = 0
  18.   where media = (a+b+c)/3
  19.  
  20. --Exercício 3
  21. ex3 :: Integer -> Integer -> (Integer,Integer)
  22. ex3 a b
  23.   | a < b = ((ex3_1 a b), (ex3_2 (a+1) b))
  24.   | a > b = ((ex3_1 b a), (ex3_2 (b+1) a))
  25.   | otherwise = (a,0) --quando a == b
  26. --função auxiliar que retorna a soma incluindo os limites. Supõe que x < y
  27. ex3_1 :: Integer -> Integer -> Integer
  28. ex3_1 x y
  29.   | x == y = x
  30.   | x < y = x + (ex3_1 (x+1) y)
  31. --função auxiliar que retorna a soma excluindo o limite superior. Supõe que x < y
  32. ex3_2 :: Integer -> Integer -> Integer
  33. ex3_2 x y
  34.   | x == y = 0
  35.   | x < y = x + (ex3_2 (x+1) y)
  36.  
  37.  
  38. --Exercício 4 (MMC)
  39. ex4 :: Int -> Int -> Int
  40. ex4 a b
  41.   |(a == b) = a --se a e b forem iguais, não é preciso fazer contas,o MMC entre eles são eles mesmos
  42.   |otherwise = ex4_1 a b 2
  43. --função auxiliar que realiza divisões e multiplica o divisor de cada iteração recursivamente, e incrementa o divisor quando nem a nem b são divisíveis por ele
  44. ex4_1 :: Int->Int->Int->Int
  45. ex4_1 a b divisor
  46.   |(a == 1) && (b == 1) = 1
  47.   |(mod a divisor /= 0) && (mod b divisor /= 0) = ex4_1 a b (divisor+1)
  48.   |(mod a divisor == 0) && (mod b divisor == 0) = divisor * ex4_1 (a`div`divisor) (b`div`divisor) divisor
  49.   |(mod a divisor == 0) && (mod b divisor /= 0) = divisor * ex4_1 (a`div`divisor) b divisor
  50.   |(mod a divisor /= 0) && (mod b divisor == 0) = divisor * ex4_1 a (b`div`divisor) divisor
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. --Exercício 6  ERRADO                                                       FAZER OUTRO
  58. ex6 :: Integer -> Integer -> Integer
  59. ex6 a b = ex6_1 a b 2
  60.  
  61. ex6_1 :: Integer -> Integer -> Integer -> Integer
  62. ex6_1 a b num
  63.   | (mod a num == 0) && (mod b num == 0) = num * (ex6_1 (a`div`num) (b`div`num) num)
  64.   | (mod a num /= 0) && (mod b num /= 0) && ((num > (a - num)) || (num > (b - num))) = 1
  65.   | otherwise = ex6_1 a b (num+1)
  66.  
  67. main = do  
  68.   --print $ ex1 1 0 0
  69.   print $ ex2 3 3 2.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement