#include<stdio.h>
#include<stdlib.h>
int main()
{
//数一下 1到 100 的所有整数中出现多少次数字9
//100中不包含9,所以我们只需要看十位和各位是否包含9
//该数关于10求余,其模为9则个位包含9;该数除以十,其商为9则十位包含9
int num;
int count=0;
for (num = 1; num < 100; num++)
{
int a = num % 10;
int b = num / 10;
if (a == 9)
{
count++;
}
if (b == 9)
{
count++;
}
}
printf("出现9的次数=%d\n", count);
system("pause");
return 0;
}
数一下 1到 100 的所有整数中出现多少次数字9
最新推荐文章于 2019-04-18 17:51:19 发布