fork download
  1. -- Instituto Tecnológico Superior de Xalapa
  2. -- Ingeniería en Sistemas Computacionales
  3. -- Nombre: Jaqueline Mota Montoya
  4. -- Matrícula: 207O02468
  5. -- Xalapa, Ver.
  6.  
  7. sumarLista :: [Int] -> Int
  8. sumarLista = sum
  9.  
  10. esPrimo :: Int -> Bool
  11. esPrimo n
  12. | n < 2 = False
  13. | otherwise = all (\x -> n `mod` x /= 0) [2..floor (sqrt (fromIntegral n))]
  14.  
  15. fibonacci :: Int -> Int
  16. fibonacci 0 = 0
  17. fibonacci 1 = 1
  18. fibonacci n = fibonacci (n - 1) + fibonacci (n - 2)
  19.  
  20. main :: IO ()
  21. main = do
  22. -- Prueba de sumarLista
  23. let lista = [1, 2, 3, 4, 5]
  24. putStrLn ("Suma de la lista " ++ show lista ++ ": " ++ show (sumarLista lista))
  25.  
  26. -- Prueba de esPrimo
  27. let numero = 7
  28. putStrLn ("¿Es " ++ show numero ++ " primo? " ++ show (esPrimo numero))
  29.  
  30. -- Prueba de Fibonacci
  31. let n = 10
  32. putStrLn ("El " ++ show n ++ "° número de Fibonacci es: " ++ show (fibonacci n))
  33.  
  34.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Suma de la lista [1,2,3,4,5]: 15
¿Es 7 primo? True
El 10° número de Fibonacci es: 55