我思故我在系列—数据结构面试NO.30题(题目搜集整理者JULY,非常感谢!!)
2011-11-04 15:27
330 查看
30.
在从1 到n的正数中1 出现的次数
题目:输入一个整数n,求从1 到n 这n 个整数的十进制表示中1 出现的次数。
从1到n进行for()循环,将每个整数中出现的1的次数求总和;
#include<stdio.h>
#include<stdlib.h>
int everycount(int num)
{
int count=0;
while(num!=0)
{
if((num%10)==1)
{
count++;
}
num=num/10;
}
return count;
}
int Numcount(int sum)
{
int num=0;
int i;
for(i=1;i<=sum;i++)
{
num+=everycount(i);
}
return num;
}
int main(int argc,char* argv[])
{
int times;
times=Numcount(100);
printf("the times of 1 is:%d",times);
return 1;
}
在从1 到n的正数中1 出现的次数
题目:输入一个整数n,求从1 到n 这n 个整数的十进制表示中1 出现的次数。
从1到n进行for()循环,将每个整数中出现的1的次数求总和;
#include<stdio.h>
#include<stdlib.h>
int everycount(int num)
{
int count=0;
while(num!=0)
{
if((num%10)==1)
{
count++;
}
num=num/10;
}
return count;
}
int Numcount(int sum)
{
int num=0;
int i;
for(i=1;i<=sum;i++)
{
num+=everycount(i);
}
return num;
}
int main(int argc,char* argv[])
{
int times;
times=Numcount(100);
printf("the times of 1 is:%d",times);
return 1;
}
相关文章推荐
- 我思故我在系列—数据结构面试NO.24(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.29题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.35题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.15(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.22,NO.23题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.28题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试题NO.17(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.33,NO.34(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构题(题目搜集整理者V_JULY_V,非常感谢!)
- 我思故我在系列—数据结构面试14题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试12,13题(题目搜集整理者V_JULY_V,非常感谢!!)
- 我思故我在系列—数据结构NO.26题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构题NO.36(题目搜集整理者july,非常感谢!!)
- 我思故我在系列—数据结构面试NO.20题将一串字符串转为整数(题目搜集整理者JVLY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.27题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.25题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构题(题目搜集整理者july,非常感谢!)
- 我思故我在系列—数据结构10题(题目搜集整理者V_JULY_V,非常感谢!!)
- 我思故我在系列—数据结构面试题(题目搜集整理者V_JULY_V,非常感谢!)
- 我思故我在系列—数据结构面试题NO.18(题目搜集整理者JVLY,非常感谢!!)