Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Exercício 1
- ex1 :: Float -> Float -> Float -> (Float,Float)
- ex1 a b c
- | b*b-4*a*c < 0 = error "delta negativo"
- | otherwise = (x1,x2)
- where
- x1 = (-b + sqrt(b*b-(4*a*c)))/(2*a)
- x2 = (-b - sqrt(b*b-(4*a*c)))/(2*a)
- --Exercício 2
- ex2 :: Float -> Float -> Float -> Integer
- ex2 a b c
- | ((a > media) && (b <= media) && (c <= media)) = 1
- | ((b > media) && (a <= media) && (c <= media)) = 1
- | ((c > media) && (a <= media) && (b <= media)) = 1
- | ((a > media) && (b > media) && (c <= media))||((a > media) && (b <= media) && (c > media))||((a <= media) && (b > media) && (c > media)) = 2
- | otherwise = 0
- where media = (a+b+c)/3
- --Exercício 3
- ex3 :: Integer -> Integer -> (Integer,Integer)
- ex3 a b
- | a < b = ((ex3_1 a b), (ex3_2 (a+1) b))
- | a > b = ((ex3_1 b a), (ex3_2 (b+1) a))
- | otherwise = (a,0) --quando a == b
- --função auxiliar que retorna a soma incluindo os limites. Supõe que x < y
- ex3_1 :: Integer -> Integer -> Integer
- ex3_1 x y
- | x == y = x
- | x < y = x + (ex3_1 (x+1) y)
- --função auxiliar que retorna a soma excluindo o limite superior. Supõe que x < y
- ex3_2 :: Integer -> Integer -> Integer
- ex3_2 x y
- | x == y = 0
- | x < y = x + (ex3_2 (x+1) y)
- --Exercício 4 (MMC)
- ex4 :: Int -> Int -> Int
- ex4 a b
- |(a == b) = a --se a e b forem iguais, não é preciso fazer contas,o MMC entre eles são eles mesmos
- |otherwise = ex4_1 a b 2
- --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
- ex4_1 :: Int->Int->Int->Int
- ex4_1 a b divisor
- |(a == 1) && (b == 1) = 1
- |(mod a divisor /= 0) && (mod b divisor /= 0) = ex4_1 a b (divisor+1)
- |(mod a divisor == 0) && (mod b divisor == 0) = divisor * ex4_1 (a`div`divisor) (b`div`divisor) divisor
- |(mod a divisor == 0) && (mod b divisor /= 0) = divisor * ex4_1 (a`div`divisor) b divisor
- |(mod a divisor /= 0) && (mod b divisor == 0) = divisor * ex4_1 a (b`div`divisor) divisor
- --Exercício 6 ERRADO FAZER OUTRO
- ex6 :: Integer -> Integer -> Integer
- ex6 a b = ex6_1 a b 2
- ex6_1 :: Integer -> Integer -> Integer -> Integer
- ex6_1 a b num
- | (mod a num == 0) && (mod b num == 0) = num * (ex6_1 (a`div`num) (b`div`num) num)
- | (mod a num /= 0) && (mod b num /= 0) && ((num > (a - num)) || (num > (b - num))) = 1
- | otherwise = ex6_1 a b (num+1)
- main = do
- --print $ ex1 1 0 0
- print $ ex2 3 3 2.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement