fork download
  1. euclid :: Int -> Int -> Int
  2. euclid a b | a <= 0 && b <= 0 = error "GCD works for Numbers"
  3. | a == b = a
  4. | a > b = euclid (a - b) b
  5. | otherwise = euclid a (b - a)
  6. main :: IO()
  7. main = do putStrLn "Enter the first number:"
  8. a <- getLine
  9. let a' = read a :: Int
  10. putStrLn "Enter the second number:"
  11. b <- getLine
  12. let b' = read b :: Int
  13. putStrLn $ "The GCD of " ++ a ++ " and " ++ b ++ " is " ++ show (euclid a' b')
  14.  
Success #stdin #stdout 0.01s 5284KB
stdin
10
3
stdout
Enter the first number:
Enter the second number:
The GCD of 10 and 3 is 1