寫正確函數須要注意的地方:給定一個十進制整數N,計算從1開始到N的全部整數出現的「1」的個數

int numOf1(int n) { int factor=1; int count=0; while(n/factor!=0) { int higher=n/(factor*10);//當前位置的高位組成的數字。 int cur=n/factor%10;//當前位置數字 int lower=n%factor;//當前位置的低位組成的數字。 if(cur==0) c
相關文章
相關標籤/搜索