本文介绍了如何确定的C中的整数的位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,
N = 3432,结果4N = 45,结果2N = 33215,导致5N = -357,导致3
我想我可能只是把它变成一个字符串,然后得到的字符串的长度,但似乎令人费解和黑客-Y。
解决方案
楼(log10的(ABS(X)))+ 1
for instance,
n = 3432, result 4
n = 45, result 2
n = 33215, result 5
n = -357, result 3
I guess I could just turn it into a string then get the length of the string but that seems convoluted and hack-y.
解决方案
floor (log10 (abs (x))) + 1
http://en.wikipedia.org/wiki/Logarithm
这篇关于如何确定的C中的整数的位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!