码迷,mamicode.com
首页 > 其他好文 > 详细

计算出1-n(n通过传参实现)中有多少个9。

时间:2017-07-10 22:19:56      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:i++   ret   for   scanf   printf   传参   include   个数   ase   

//计算出1-n(n通过传参实现)中有多少个9。
#include<stdio.h>

int main()
{
    int n;

    printf("Please input a number:\n");
    scanf("%d",&n);

    fun(n);

    return 0;
}


void fun(int n)

    int i,a,b;
    int count = 0;

    for(i = 1;i <= n;i++)
    {
        a = i;
	while(a != 0)
	{
	    b = a % 10;
	    a = a / 10;
	    if(b == 9)
	    {
	        count++;
	    }
	}
    }
    printf("9的个数是:%d\n",count);


}

计算出1-n(n通过传参实现)中有多少个9。

标签:i++   ret   for   scanf   printf   传参   include   个数   ase   

原文地址:http://www.cnblogs.com/Janskid/p/7147602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!