1到 100 的所有整数中出现数字9的次数

获取个位数:N%10
获取十位数:N/10

#include<stdio.h>
int  main() {
	int count = 0;
	for (int i = 1; i <= 100; i++) {
		if (i % 10 == 9) {
			count++;
		}
		if (i / 10 == 9) {
			count++;
		}
	}
	printf(" 1到 100 的所有整数中出现数字9的次数为:%d", count);
}

猜你喜欢

转载自blog.csdn.net/weixin_43788418/article/details/84830902
今日推荐