scanf("%d",&a);
for(b=1;b<=a;++b)
{
c*=b;
}
printf("%lu",c);
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?
scanf("%d",&a);
for(b=1;b<=a;++b)
{
c*=b;
}
printf("%lu",c);
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?
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 asINT_MAX
in<limits.h>
.100!
will obviously far exceed this. To calculate something this large inC
, you'll need a big integer library, such as GMP.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 are48
, which is obviously nonsense:100!
must be divisible by 100, hence must have00
as the last two digits.For small numbers you better use
unsigned long long
thanint
. But still you have limit on the biggest number you can use fora
. You could trydouble
orfloat
but you might get precession error.