LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Product of first N odd numbers

Solved!
Go to solution

Here is how I roll:

 

SumEvenProductOdd.png

 

Likely homework so explanations are left as an exercise for the reader...

Message 11 of 20
(926 Views)

Of course one quickly runs out of digits and the entire thing could actually be implemented as a lookup table for all useful inputs.

 

A more interesting solution would be something that can produce results with thousands of significant digits. 😉 (look here for some ideas )

0 Kudos
Message 12 of 20
(918 Views)

Ok, that's the end of the line - slightly faster than I - needed too much time to think about the odd product 😮

0 Kudos
Message 13 of 20
(916 Views)

@altenbach wrote:

Of course one quickly runs out of digits and the entire thing could actually be implemented as a lookup table for all useful inputs.

 

A more interesting solution would be something that can produce results with thousands of significant digits. 😉 (look here for some ideas )


In this case I would go for something like phython with the mpmath library.

0 Kudos
Message 14 of 20
(902 Views)

For N=0 the product is 1. Thank you all for the solutions. I will check them all to understand them and to see which fits better.

0 Kudos
Message 15 of 20
(898 Views)

0 is an even number, so this is irrelevant for the problem. However if you want a product result of 1 if N=0, that can easily be implemented. Is zero even allowed as input for your problem. Hard to tell unless we know all the requirements.

0 Kudos
Message 16 of 20
(890 Views)

If 0 is an even number the sum should be 0 and the product also 0.

0 Kudos
Message 17 of 20
(886 Views)

@SebiC98 wrote:

For N=0 the product is 1. Thank you all for the solutions. I will check them all to understand them and to see which fits better.


Here's the tiny change to fix this. See if you understand why. 😉

 

(The product of an empty array is of course also 1, so some of the conditional indexing solutions will probably work too)

 

(I also went to U64, but overflow still occurs if the numbers are getting a bit larger, of course)

 

altenbach_0-1604133488536.png

 

Message 18 of 20
(880 Views)

Thank you verry much. Have a great day!

0 Kudos
Message 19 of 20
(875 Views)

@SebiC98 wrote:

If 0 is an even number the sum should be 0 and the product also 0.


No. As I said 0 factorial is 1 and the product of an empty array is also 1, so the correct result for N=0 should probably be one, because the list of odd number is an empty array. See also my other answer.

0 Kudos
Message 20 of 20
(874 Views)