问题
Who can help me out with a QBASIC CODE to find the permutation of a given number. I'd really appreciate. I've tried writing some codes but it's not giving the required answer.
回答1:
If by permutation you mean the factorial then the following is the code that you need. It will get an integer and compute its factorial.
DECLARE FUNCTION Factorial (n)
FUNCTION Factorial (n)
IF n = 0 THEN
Factorial = 1
ELSE
Factorial = n * Factorial(n - 1)
END IF
END FUNCTION
INPUT "PLEASE ENTER AN INTEGER", n
PRINT n;"! = "; Factorial(n)
But if by permutation you mean all of the permutations of the sequence 1,...,n then it is another story. So let me know in the comments.
来源:https://stackoverflow.com/questions/60205306/is-there-a-special-formula-for-permutation