Ajude o blog! PIX para doações: 6d8bc7a8-5d74-493a-ab7a-3515baf35956
Vamos resolver mais um exercício em Haskell!
Agora o problema Average 1 (Média 1)! Bora?!
Plataforma: Beecrowd (antiga URI)
In english:
Read two floating points' values of double precision A and B, corresponding to two student's grades. After this, calculate the student's average, considering that grade A has weight 3.5 and B has weight 7.5. Each grade can be from zero to ten, always with one digit after the decimal point. Don’t forget to print the end of line after the result, otherwise you will receive “Presentation Error”. Don’t forget the space before and after the equal sign.
Linguagem: Haskell
Solução:
Aqui para formatar a saída como no exercício, com cinco casas decimais, é útil fazer uso da função printf, com %.5f ela formata com 5 casas decimais após a vírgula.
Eu usei let para guardar o valor do cálculo da média em "media". No entanto, isso não seria necessário. Abaixo fiz os códigos das duas formas, você pode testá-los na plataforma e verá que os dois são aceitos.
Aqui com let:
import Text.Printf (printf)
main :: IO ()
main = do
a <- readLn :: IO Double
b <- readLn :: IO Double
let media = (a * 3.5 + b * 7.5) / 11.0
printf "MEDIA = %.5f\n" (media)
Aqui sem let:
import Text.Printf (printf)
main :: IO ()
main = do
a <- readLn :: IO Double
b <- readLn :: IO Double
printf "MEDIA = %.5f\n" ((a * 3.5 + b * 7.5) / 11.0)