Is there a special formula for permutation

前提是你 提交于 2020-07-23 09:23:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!