编写程序统计1到100的所有整数中出现9的次数

编写程序统计1到100的所有整数中出现9的次数
c语言中:
x%10表示整数中的个位数
x/10%10表示整数中的十位数
x/100表示百位…以此类推

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

猜你喜欢

转载自blog.csdn.net/Amoralmmm/article/details/93136311
今日推荐