落書きノート

ふと自分が気になった事を書いてます

Haskellで不定期練習

import Text.Printf

main :: IO ()

f n
  | n >= 0 && n <= 59 = "不可"
  | n >= 60 && n <= 69 = "可"
  | n >= 70 && n <= 79 = "良"
  | n >= 80 && n <= 100 = "優"
  | otherwise = "不正な点数です。"
  
main = do
  putStrLn "点数 : "
  v <- getLine
  let point = read v :: Int
  putStrLn $ f point


import Text.Printf

main :: IO ()
main = do
  putStrLn "実数a"
  v1 <- getLine
  putStrLn "実数b"
  v2 <- getLine
  let a = read v1 :: Float
      b = read v2 :: Float
  if a > b then printf "大きいほうの値は%.1fです。\n" a
    else printf "大きいほうの値は%.1fです。\n" b



import Text.Printf

main :: IO ()
main = do
  putStrLn "整数a"
  v1 <- getLine
  putStrLn "整数b"
  v2 <- getLine
  let a = read v1 :: Int
      b = read v2 :: Int
  printf "それらの差は%dです。\n" $ if a > b then a - b else b - a



import Text.Printf

main :: IO ()
main = do
  putStrLn "整数A"
  v1 <- getLine
  putStrLn "整数B"
  v2 <- getLine
  let a = read v1 :: Int
      b = read v2 :: Int
      answer = if a > b then a - b else b - a
  if answer <= 10 then printf "それらの差は10以下です。\n"
    else printf "それらの差は11以上です。\n"



import Text.Printf
import Data.IORef

main :: IO ()
main = do
  putStrLn "整数a"
  v1 <- getLine
  putStrLn "整数b"
  v2 <- getLine
  putStrLn "整数c"
  v3 <- getLine
  let a = read v1 :: Int
      b = read v2 :: Int
      c = read v3 :: Int
  min <- newIORef a
  t <- readIORef min
  writeIORef min $ if t > b then b else t
  t <- readIORef min
  writeIORef min $ if t > c then c else t
  printf "最小値は%dです。\n" =<< readIORef min