方法一
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,count=0,a,b;
for (i = 1; i <= 100; i++)
{
a= i / 10;
b = i % 10;
if (a == 9)
{
count++;
}
if (b == 9)
{
count++;
}
}
printf("出现数字9的个数为%d\n", count);
system("pause");
return 0;
}
方法二
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,count=0;
for (i = 1; i <= 100; i++)
{
if (((i - 9) % 10 == 0) || (i % 10 == 9))
{
count++;
if (((i - 9) % 10 == 0) && (i % 10 == 9))
{
count++;
}
}
}
printf("出现数字9的个数为%d\n", count);
system("pause");
return 0;
}