在這個函式中計算一個數的階乘:
int fact(int n) {
if (n == 0 || n == 1)
return 1;
else
return n * fact(n - 1);
}
如何添加條件
if(n<0)
cout <<"Error negative values are not accepted";
//Here I want to add something that makes me exit the function and stop the code after the cout statement is printed
uj5u.com熱心網友回復:
您可以std::exit()在 cout 陳述句之后使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/421385.html
標籤:
上一篇:PHP類函式
下一篇:我需要通過我的代碼進行解釋,我們需要在哪里定義init方法并宣告“self”。如何在每種情況下呼叫函式在我的代碼中給出
