2016-04-08 102 views

回答

1

爲了得到一個整數數的長度,你可以不喜歡這個 -

int length = ceiling(log10(number)); 

但是這樣的方法會更efficient-

int countLength(int number){ 
    if(number>9) return countLength(number/10) + 1; 
    return 1; 
}