LabVIEW Digest Programming Challenges

Reply
This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.

Re: LabVIEW Digest Challenge 2

Heres mine!

 

(Small edit: didn't handle zero before)

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 11 of 15
(930 Views)

Re: LabVIEW Digest Challenge 2

Hi Everyone, 

 

It looks like I might have done a competition that was a bit too easy this time around! We've had a lot of correct answers.

 

This challenge's winner is sankar06! I'm working on getting you your free certification exam now! Congratulations!

 

We'll be back with another challenge in the next few months so keep an eye out for the next LV Digest

Winner.pngWinning entry - nice use of an already inbuilt function and reversing the problem

 

Here are some of our other entries, all quite different from each other.

 

Highlight - nice checking that the number is positive with the case structure!

Example 1.pngThanks to James_McN for this one.

 

Another different example again, using some best programming practices here with the wait for ms function. Always good to make it a habit!

Example 2.pngThanks to Iarall for this one

This was the only VI I checked that properly accounted for the fact that the number 1 can be both 0! and 1!. Something I hadn't considered myself.

Example 3.pngThanks to CJWalker for this one

Message 12 of 15
(861 Views)

Re: LabVIEW Digest Challenge 2

Not relevant. Please skip

0 Kudos
Message 13 of 15
(571 Views)

Re: LabVIEW Digest Challenge 2


@chandrahasd23 wrote:

Simplest way to find the factorial of a number


  • This thread is about the reverse function, so your code is offtopic. Besides, we already have that function.
  • Since you only operate on I32, you'll quickly get wraparound and incorrect results, even negative results!
  • The input is N and the output is Factorial(N), so don't name the input "factorial" and the output "Result", confusing the user.
  • The indicator belongs after the FOR loop. There is absolutely no need to display intermediary values which have nothing to do with the result..
  • The input needs to be an integer, it cannot be fractional. Change to the correct representation.
  • There is a +1 primitive, no need for the diagram constant.

In summary, you code is not the "simplest way". It's not even the correct way! Smiley Very Happy

 

To calculate a factorial, even is the result has tens of thousands of digits, have a look here:

 

SimpleFactorial

 

 

 

 


LabVIEW Champion Do more with less code and in less time
Message 14 of 15
(565 Views)

Re: LabVIEW Digest Challenge 2

This is my solution.

HOB Consultores S.A.
Área de Investigación, Desarrollo e Innovación Tecnológica
0 Kudos
Message 15 of 15
(283 Views)
Reply
This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.