Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Nome das funcoes: Fatorial (int x), Multiplicar(Int x, Int y), Mdc(Int x,Int y), sub(Int x, Int y). Os metodos subP e subN devem ser --privados
- -- Fatorial
- -- Condição de saida
- Fatorial::Int->Int
- Fatorial 0 = 1
- -- Recursao
- Fatorial x = x * (Fatorial (x-1) )
- -- multiplicações com somas repetidas
- Multiplicar :: Int -> Int -> Int
- -- Condição de saida
- Multiplicar x 1 = x
- -- Recursao
- Multiplicar x y = x+(Multiplicar x (y-1))
- --Maximo divisor comum
- Mdc::Int->Int->Int
- -- Condição de inversão
- Mdc x y | x < y = Mdc y x
- --Condição de saida
- | y == 0 = b
- -- Recursao
- | otherwise = Mdc y (x 'mod' y)
- -- Subtração por somas repetidas de 1 no resultado e no subtraendo, inverte caso seja negativo
- sub::Int->Int->Int
- sub x y
- --Saida simples
- | x == y = 0
- --Verifica se x é menor que Y pra fazer subtração de negativos
- | x < y = subN y x 0
- | otherwise = subP x y 0
- --Subtração negativa, resultado multiplica por -1
- subN::Int->Int->Int->Int
- subN x y result
- --Condição de saida
- | x == y =result*(-1)
- --Recursao
- | otherwise=subN x (y+1) (result+1)
- --Subtração positiva
- subP::Int->Int->Int->Int
- subP x y result
- --Condição de saida
- | x == y =result
- --Recursao
- | otherwise=subP x (y+1) (result+1)
Add Comment
Please, Sign In to add comment