题目描述
"6"这个数字,代表“顺”。
现在给出一个大于1的正整数n,请你求出在1到n的正整数中,至少有一个数位含有6的正整数个数。
考试快结束了,借此题祝各位考试顺利!科科100分
新年也快到了,借此题祝各位在新的一年里,做什么都是顺顺顺!
输入
输入一个大于1的正整数n。(1<=n<=10 000)
输出
输出含有6的正整数个数。
样例输入 Copy
100
样例输出 Copy
19
#include<stdio.h>
int f(int x)//找到带有6的数字
{
int k;
while(x)
{
k=x%10;
if(k==6)return 1;
x=x/10;
}
return 0;
}
int main()
{
int n,i,count=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(f(i)==1)count++;
}
printf("%d",count);
}