# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## To check given number is Factorial of number or not

I have a problem, i given some input number n, we have to check whether the no is factorial of some other number or not.

For example 24 if i enter it is a factorial of 4.

Help me

Message 1 of 7
(6,135 Views)

## Re: To check given number is Factorial of number or not

Hi Ali,

I have a problem

- Do you want to learn LabVIEW? Ask NI!

- Do you want to know how to determine prime numbers? Ask Wikipedia!

- Do you have a problem with your specific VI? Attach it!

Best regards,
GerdW

using LV2016/2019/2020 on Win8.1/10+cRIO
Message 2 of 7
(6,113 Views)

## Re: To check given number is Factorial of number or not

This is a simple problem, because the possible values are all integers and the function is always increasing and thus has no complicated behavior. The simple way would be to divide by successive increasing integers and if you end up at 1 you started with a factorial, else not.

The complication is that only very few factorials can be accurately represented in e.g. DBL or U64, and these can all be calculated nearly instantaneously, so you could simple make a lookup table.

How many digits do you allow for the input? You can do math with huge number of digits and get e.g. all 35660 digits of 10000! (exampleSo if you want to allow very large inputs, things get a bit more interesting. What is the allowed range of inputs?

Message 3 of 7
(6,102 Views)
Solution
Accepted by ali9963

## Re: To check given number is Factorial of number or not

@ali9963 wrote:

I have a problem, i given some input number n, we have to check whether the no is factorial of some other number or not.

For example 24 if i enter it is a factorial of 4.

This sounds familiar...LabVIEW Digest Challenge 2

My solution was also the lookup table.  But there are some interesting solutions in there.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 7
(6,076 Views)

## Re: To check given number is Factorial of number or not

@crossrulz wrote:
This sounds familiar...LabVIEW Digest Challenge 2

How come I have never heard of that group? 😮 (just joined!)

@crossrulz wrote:
My solution was also the lookup table.  But there are some interesting solutions in there.

Would have been interesting to expand it to inputs with thousands of digits. 😄

Message 5 of 7
(6,050 Views)

## Re: To check given number is Factorial of number or not

@altenbach wrote:

@crossrulz wrote:
This sounds familiar...LabVIEW Digest Challenge 2

How come I have never heard of that group? 😮 (just joined!)

Poor organization of the community?

Due note that the challenges are technically only open to Europe, Middle East, India and Africa.  So no prizes for me.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 7
(6,048 Views)
Solution
Accepted by ali9963

## Re: To check given number is Factorial of number or not

@crossrulz wrote:

@altenbach wrote:

@crossrulz wrote:
This sounds familiar...LabVIEW Digest Challenge 2

How come I have never heard of that group? 😮 (just joined!)

Poor organization of the community?

Due note that the challenges are technically only open to Europe, Middle East, India and Africa.  So no prizes for me.

We don't need prizes to show them how to really program something 😄

Seriously, though, it would be nice to bring back regular (global!) coding challenges.

Message 7 of 7
(6,035 Views)