19.3 Write an algorithm which computes the number of trailing zeros in n factorial.
int numOfZerosInNFactory(int n) { // 5 -> 1 // 10 -> 1 if (n < 1) return 0; int toReturn = 0; while (n > 0) { n = n / 5; toReturn += n; } return toReturn; }
furuijie8679 博主文章分类:Interview ©著作权
19.3 Write an algorithm which computes the number of trailing zeros in n factorial.
int numOfZerosInNFactory(int n) { // 5 -> 1 // 10 -> 1 if (n < 1) return 0; int toReturn = 0; while (n > 0) { n = n / 5; toReturn += n; } return toReturn; }
上一篇:CC150 19.2
下一篇:CC150 19.4
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M