C语言:编写程序数一下 1到 100 的所有整数中出现多少次数字9。

#include <stdio.h>
#include <stdlib.h>
int main()
{
	int i = 0;
	int count = 0;
	for (i = 1; i <= 100; i++)
	{
		if (i / 10 == 9)
		{
			count++;
		}
		if (i % 10 == 9)
		{
			count++;
		}
	}
	printf("出现9的次数为:%d\n次", count);
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42270373/article/details/81135905