# Thread: product of even numbers

1. ## product of even numbers

Hello.
I am trying to create a c program that finds the product of even numbers from 10 to 100. can someone help me? I did the program but the compiler give me the product as 0, but when I try smaller numbers like from 10 to 30 it works. What could be the problem?

2. Post your current code in [code][/code] tags. This is the C++ forum section, there's a separate C section (no pun intended).

3. You want the product of even numbers from 10 to 100. Let's call it from 2 to 100 for simplicity. That's 2 * 4 * 6 * ... * 100 which is 2*(1*2*3*...*50) which is 2 * 50! (50 factorial). 50! is a very very large number, and not counting the product of the even values less than 10 barely makes a dent in it.

50! = 30414093201713378043612608166064768844377641568960 512000000000000 (65 digits long)

The product of evens from 10 to 30 is of the order 15! which is 1,307,674,368,000. So that fits in a 64-bit integer.

Anyway, multiplying 10*12*14*...*100 will wrap around again and again and it only has to become 0 once in the multiplication of factors to make the result 0.

4. My magical senses tell me that you initialized the variable that holds the product to 0. It should be 1, because remember 0 x anything will give you 0. Whereas 1 x anything will give you the number you multiplied with 1. Use that to your advantage!

And you should be using a for-loop with an iterator initialized to 10 until 100 which increments by 2.

But like john.c said the actual answer itself would be VERY big, so big that no standard datatype in C++ can store it. So make sure that we're talking about product and not SUM over here. Otherwise you need to use a non-standard datatype that can hold such a value like bigint.

5. Originally Posted by Nwb
My magical senses tell me that you initialized the variable that holds the product to 0. It should be 1, because remember 0 x anything will give you 0.
That would be a good guess if all of relwan's tests resulted in 0, but "when I try smaller numbers like from 10 to 30 it works", hence relwan could not have initialised that variable to 0.

6. Oh I totally missed that line laserlight..