编写程序数一下 1到 100 的所有整数中出现多少次数字9:
数: 9 19 29 39 49 59 69 79 89 90
91 92 93 94 95 96 97 98 99
个位上的数是9:i % 10=9;
十位上的数是9:i / 10=9;
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("%d\n", count);
system("pause");
return 0;
}
找出多少个含有9的数字:
此时99算一个
int main(){
int i = 0;
int count = 0;
for (i = 1; i < 100; i++){
if (i % 10 == 9){
count++;
}
else if (i / 10 == 9){
count++;
}
}
printf("%d\n", count);
system("pause");
return 0;
}
biubiu~