0的个数

 1 #include <iostream>
2 using namespace std;
3
4 #include <stdlib.h>
5 #include <sys/types.h>
6
7 int Count(int n)
8 {
9 int count = 0;
10 while (n) {
11 count += n / 5;
12 n /= 5;
13 }
14 return count;
15 }
16
17 int main()
18 {
19 cout << Count(26) << endl;
20
21 return 0;
22 }

1的位置

 1 #include <iostream>
2 using namespace std;
3
4 #include <stdlib.h>
5 #include <sys/types.h>
6
7 int Count(int n)
8 {
9 int count = 0;
10 while (n) {
11 count += n / 2;
12 n /= 2;
13 }
14 return count + 1;
15 }
16
17 int main()
18 {
19 cout << Count(4) << endl;
20
21 return 0;
22 }





posted on 2011-10-21 14:33  吃吃户  阅读(292)  评论(0编辑  收藏  举报