统计一个整数中包含1的个数
2009-09-11 10:59 hailibu 阅读(238) 评论(0) 编辑 收藏 举报 1private int CountOne(int num)
2{
3 int count = 0;
4 while (num != 0)
5 {
6 count += num % 10 == 1 ? 1 : 0;
7 num /= 10;
8 }
9 return count;
10}
2{
3 int count = 0;
4 while (num != 0)
5 {
6 count += num % 10 == 1 ? 1 : 0;
7 num /= 10;
8 }
9 return count;
10}