Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mySum :: [Int] -> Int
- mySum [] = 0
- mySum (a:as) = a + mySum as
- myProduct :: [Int] -> Int
- myProduct [] = 1
- myProduct (a:as) = a * myProduct as
- myPow :: Int -> Int -> Int
- myPow b e
- | e == 0 = 1
- | e == 1 = b
- | otherwise = b * myPow b (e - 1)
- size :: [Int] -> Int
- size [] = 0
- size (a:as) = 1 + size as
- nesimo :: Int -> [Int] -> Int
- nesimo n (a:as)
- | n == 0 = a
- | otherwise = nesimo (n - 1) as
- inverter :: [Int] -> [Int]
- inverter [] = []
- inverter (a:as) = inverter as ++ (a:[])
- main :: IO ()
- main = do
- putStrLn $ "Soma dos elementos da lista: " ++ show (mySum [1, 2, 3, 4, 5])
- putStrLn $ "Produto dos elementos da lista: " ++ show (myProduct [1, 2, 3, 4, 5])
- putStrLn $ "Tamanho da lista: " ++ show (size [1, 2, 3, 4, 5])
- putStrLn $ "Potenciacao b ^ e: " ++ show (myPow 2 1)
- putStrLn $ "Nesimo elemento da lista (2): " ++ show (nesimo 2 [3, 4, 7, 9, 12])
- putStrLn $ "Inverter lista: " ++ show (inverter [1, 2, 3, 4, 5])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement