I am sure there is a simpler mathematical solution but this is good enough for now I have always been a brute force guy sadly
#include<stdio.h>
void main()
{
int i;
long double p=1;
for(i=1;i<101;i++)
{
p=p*i;
}
printf("Product of all numbers between 1&100 is %LG \n",p);
}No Compiler installed no issues head to http://codepad.org/
PS:-
The answer is 152 zeroes.
My takeaway from this is the printf Format placeholder for Long Double-%LG
Actually, there is a better (and more accurate way.
Note that your double isn’t large enough to hold a value as large as 100!, neither is the unsigned long. But Java does have the BigNumber object that can be used to store numbers larger than you can imagine.
[EDIT] I’m not sure about this. I didn’t remember the long double extended-precision format. Assumed it was 64-bits like the double. Rahul pointed out that it was indeed capable of storing values as large enough as 100!
What you’d have to do in C is to keep an array to keep track of all those digits and then perform the computation as if you were writing it down on pen and paper, take each thing one-by-one and multiply.
I will work on a possible solution to this.