趣味100道C語言程式num four

2021-07-14 18:29:00 字數 1482 閱讀 2864

求階乘位數0的個數

例如:求:100!的末尾有多少個0

分析:顯然100!的位數超出已知基本資料型別的範圍,所以不能單純的先求取出100!的數值,再判斷末尾有多少個0.尋找規律可以發現,該問題可以轉換成1~100的100個整數一共有多少個因數5,的問題。

程式如下:

#include int main()

}printf("the number of 0 in the end of 100! is %d\n",num);

return 0;

}

除錯結果如下:

the number of 0 in the end of 100! is 24
那要求1000!的位數有幾個0又應該怎麼辦?

例程:

#include int main()}}

}printf("the number of 0 in the end of 1000! is %d.\n",num);

return 0;

}

除錯結果為:

the number of 0 in the end of 100! is 24

由此,我們可以得出一般情況n!的位數有幾個0

例程:

#include int main()

else

else}}

}printf("the number of 0 in the end of %d! is %d.\n",n,num);

return 0;

}[root@localhost funny]# cat weishu_plus.c

//求100!的末尾的0的個數

#include int main()

}printf("the number of 0 in the end of 100! is %d\n",num);

return 0;

}

除錯結果為:

please input the number:

4the number of 0 in the end of 4! is 0.

please input the number:

5the number of 0 in the end of 5! is 1.

please input the number:

100the number of 0 in the end of 100! is 24.

please input the number:

1000

the number of 0 in the end of 1000! is 249.

please input the number:

555the number of 0 in the end of 555! is 137.

c語言趣味100例 窮舉迴圈

窮舉迴圈 對於不定方程,可以利用窮舉迴圈的方法來解決,就是通過對未知數可變範圍的窮舉,驗證方程在什麼情況下成立,從而得到相應的解。1.百雞百錢問題 不定方程 cock hen chicken 100 5xcock 3xhen chicken 3.0 100 示例 intcock,hen,chicke...

c語言趣味程式設計100例 迭代迴圈

迭代迴圈 即是乙個不斷用新值取代變數的舊值,然後由變數舊值遞推出變數新值的過程,這種迭代與如下因素有關 初值,迭代公式,迭代次數。1.兔子產子問題 演算法可以描述為 fib fib2 1 n 1,2 初值 fibn fib n 1 fib n 2 n 3 迭代公式 程式如下 long fib1 1,...

c語言趣味程式設計100例 求車速

問題 求車速 一輛以固定行駛的汽車 司機在上午10點看歷程表上的讀數是乙個對稱數 既這個數從左往右和從右往左 完全是一樣的 為95859 兩個小時候歷程表上出現了乙個新的對稱數 該數稱為五位數 問該車的速度是多少 新的對稱數是多少 思路 我們可以從條件中獲取到對稱數是第一位與第五位一致 第二位和第四...