从1到100的整数中出现了多少次9

#include<stdio.h>
#include<stdlib.h>
int main(){
	int count=0;
	for (int i = 1; i < 101; i++){
		if (i % 10 == 9){  //判断个位数为9
			count++;
		}
		if (i / 10 == 9){  //判断十位数为9
			count++;
		}
	}
		printf("一共含有%d个9\n", count);
		system("pause");
		return 0;
}

猜你喜欢

转载自blog.csdn.net/sun_105/article/details/92783053