我正在尝试实现尾递归阶乘计算器,但仍然出现堆栈溢出。谁能帮我找出原因?
代码:
package factorielRecursiveTerminale;
import java.math.BigInteger;
import java.util.Scanner;
public class factorielRecursiveTerminale {
public static BigInteger factoriel(BigInteger n, BigInteger m) {
if (n.compareTo(BigInteger.ZERO) < 1) return m;
return factoriel(n.subtract(BigInteger.ONE), n.multiply(m));
}
public static BigInteger fact(int n) { //convertir l'entree en BigInteger et lancer la recursion
if(n < 0) {
return BigInteger.valueOf(-1);
}
BigInteger b = BigInteger.valueOf(n);
return factoriel(b, BigInteger.ONE);
}
public static void runBigFact() { //gestion des erreurs + boucle d'entree de …Run Code Online (Sandbox Code Playgroud) 我希望能够从我的 C++ 程序中运行 30 行 PowerShell 脚本。我听说这是一个糟糕的主意,我不在乎。我还是想知道怎么做。
我只想直接在 C++ 程序中编码,我不想从外部调用 PowerShell 脚本。有没有办法做到这一点?如果不可能,就说不。
例如
void runPScode() {
//command to tell compiler the following is PowerShell code
//a bunch of PowerShell code
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我一直在寻找执行此操作的命令并阅读了几个“类似”的问题。