#include <stdio.h>
int fun(int n)
{
int i;
int tmp;
int k;
int count = 0;
for(i=1;i<=n;i++)
{
tmp = i;
while(tmp != 0)
{
if(tmp == 9 || k == 9)
{
count++;
}
k = tmp % 10;
tmp = tmp / 10;
}
}
return (count-1);
}
int main()
{
int num;
int count = 0;
printf("Please input n:");
scanf("%d",&num);
count = fun(num);
printf("the number of 9 between 1 and %d is:%d\n",num,count);
return 0;
}
通过编程实现,统计1~n有多少个9 提示:n通过参数传入
最新推荐文章于 2019-01-25 21:56:09 发布