要注意的是,99里面有两个9,要算两次。
int main()
{
int i = 0;
int count = 0;
for (i = 1; i <= 100; i++)
{
if (i % 10 == 9 ) //9,19,29,39,49,59,69,79,89,99
count++;
if(i / 10 == 9) //90,91,92,93,94,95,96,97,98,99
count++;
}
printf("%d", count);
return 0;
}
要注意的是,99里面有两个9,要算两次。
int main()
{
int i = 0;
int count = 0;
for (i = 1; i <= 100; i++)
{
if (i % 10 == 9 ) //9,19,29,39,49,59,69,79,89,99
count++;
if(i / 10 == 9) //90,91,92,93,94,95,96,97,98,99
count++;
}
printf("%d", count);
return 0;
}