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.
Have no reason to make a 26 things to do before I turn 27 list. That should sum it up.I have never really been into new years resolutions and such so instead I am working on a “25 things to do before I turn 26” list. I have a bunch already but what would you suggest?
Number Pyramid.
I joined Java Ranch today. This is a screenshot I took to help answer a query on the forums.
Somebody needed help with a number pyramid. :-)
This required a lot of tweaking of code.
It’s Not Fair by Lily Allen
I don’t know if she’s British, but she’s fairly frowny in this video. The ‘nought’ gives it away. :-)
And I like the 70s talk show look.
