将Int划分为Int并返回Int [英] Divide Int to Int and return Int
本文介绍了将Int划分为Int并返回Int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个获取两个 Int
s( a
和 b
)并返回
A / B
作为 Int
。我相信 A / B
总是一个整数。
这是我的解决方案:
myDiv :: Int - > Int - > Int
myDiv ab =
let x = fromIntegral a
y = fromIntegral b
truncate(x / y)
但是想找到更简单的解决方案。像这样:
myDiv :: Int - > Int - > Int
myDiv ab = a / b
如何将Int分配给Int并获取Int ?
解决方案
为什么不只是使用 quot
?
quot ab
是整数a和b被截成零的整数商。
I need a function which gets two Int
s (a
and b
) and returns A/B
as Int
. I am sure that A/B
will always be an integer.
Here is my solution:
myDiv :: Int -> Int -> Int
myDiv a b =
let x = fromIntegral a
y = fromIntegral b
in truncate (x / y)
But want to find more simpler solution. Something like this:
myDiv :: Int -> Int -> Int
myDiv a b = a / b
How can I divide Int to Int and get Int ?
解决方案
Why not just use quot
?
quot a b
is the integer quotient of integers a and b truncated towards zero.
这篇关于将Int划分为Int并返回Int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文