在C中的最大数 [英] The biggest number in C

查看:115
本文介绍了在C中的最大数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scanf("%d",&a);
for(b=1;b<=a;++b)
{
    c*=b;
}
printf("%lu",c);

我要得到100的答案!结果
100阶乘。
我怎样才能得到呢? (我想获得更大范围的数字)
我们不能有数量限制为无穷大?

I want to get the answer of 100!
factorial of 100. how can I get this? ( I wanna get a bigger range of numbers) Cant we have the number limit to infinity?

推荐答案

最大整数的范围是,在几乎每一个(现代)平台, 2 ^ 31 - 1 (虽然,由标准, INT 只需要至少16位)。为了您给定的平台,它会被定义为 INT_MAX &LT;&limits.h中GT;

Max integer range is, on just about every (modern) platform, 2^31 - 1 (although, by the standard, int is only required to be at least 16 bits). For your given platform, it'll be defined as INT_MAX in <limits.h>.

100 <!/ code>显然会远远超过这个。为了计算这个东西在大 C ,你需要一个大的整数库,如 GMP

100! will obviously far exceed this. To calculate something this large in C, you'll need a big integer library, such as GMP.

正如一个谨慎注意,如果你决定尝试并使用双击(可容纳这种规模的数字),你会得到错误的答案,由于precision损失。这很容易被发现 - 我的机器上,最后一个数字是 48 ,这显然是无稽之谈: 100 必须!可以被100整除,因此必须有 00 作为最后两位数字。

Just as a cautionary note, if you decide to try and use a double (which can hold numbers of this size), you will get the wrong answer due to precision loss. This is easy to spot - on my machine, the last digits are 48, which is obviously nonsense: 100! must be divisible by 100, hence must have 00 as the last two digits.

这篇关于在C中的最大数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆