Life.src

Dec 07

Dec 05

Finding the Number of zeroes in the product of all numbers between 1 and 100

rahuljose:

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.

Dec 02

[video]

Dec 01

[video]

Nov 29

How To UnForget

Nov 28

List.

hrrrthrrr:

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?

Have no reason to make a 26 things to do before I turn 27 list. That should sum it up.

Nov 25

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.

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.

Nov 24

[video]

Autocomplete This -

There’s an autocomplete meme!

I’ll say that again:

There IS an autocomplete meme!

Thanks @g0

Also, as my very smart and very funny and very witty friend would like to point out, this is her pick of the whole lot.

I just giggled through the list.