2015-04-07 69 views
-2

我知道如何計算階乘的數字,方法如下。如何計算最有效的階乘數字

讓數字n!被發現。

temp = 0.0; 
for(i = 1; i <= n; i++){ 
temp += log(i); 
} 
result = (int)temp; 
result++; 

我在這裏尋找更有效的方法來計算階乘的位數。

注:請用C++

+1

我不確定你提供的代碼甚至可以工作。有什麼用' 結果++; =(int)temp;'?? – coyotte508

+0

這是我的錯誤。現在糾正了。謝謝 – mhkm

回答

-1

這個問題的Python的解決方案編碼答:

len(list(str(num))) 

中下計算的數字每一個數字,你可以使用此代碼:

int c=2; 
while((num/10)>10) { 
    num=(int)a/10; 
    c++; 
    } 
+0

我不知道如何編寫這種方式#Sara_Santana – mhkm

+0

你不知道python還是沒有python?如果你沒有python,你可以使用在線解釋器,如:[link](http://repl.it/languages/Python) –

+1

我不明白這有助於回答問題 – thecoshman