D3.3 编写程序数一下 1到 1000 的所有整数中出现多少次数字9。

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, count = 0;

    for (i = 1; i <= 1000; i++)
    {
        if (i % 10 == 9)
        {
            count++;
        }
        if (i / 10 % 10 == 9)
        {
            count++;
        }
        if (i / 100 == 9)
        {
            count++;
        }
    }

    printf("%d\n", count);
    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/canvasa/article/details/88813325
今日推荐