如题所述
void main(){
int n ,m,k;
printf("请输入一个8位数的数字:");
scanf("%d", &n);
if (n < 10000000 || n>99999999){
printf("输入的数不符合8位的要求!\n");
return;
}
m = n;
k = 0;
while (m > 0){
if (m % 10 == 7) k++;
m /= 10;
}
cout <<"共有"<<k<<"个7."<< endl;
system("pause");
}
int n ,m,k;
printf("请输入一个8位数的数字:");
scanf("%d", &n);
if (n < 10000000 || n>99999999){
printf("输入的数不符合8位的要求!\n");
return;
}
m = n;
k = 0;
while (m > 0){
if (m % 10 == 7) k++;
m /= 10;
}
cout <<"共有"<<k<<"个7."<< endl;
system("pause");
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2017-12-16
#include <>
int countNumber(int number, int countNumber) { //统计number中有多少个countNumber
int count=0;
if (number<0) number=-number;
while (number>0) {
if (number%10==countNumber) {
count++;
}
number/=10;
}
return count;
}
int main() {
int number;
scanf("%d",&number);
printf("%d\n",countNumber(number, 7));
return 0;
}
int countNumber(int number, int countNumber) { //统计number中有多少个countNumber
int count=0;
if (number<0) number=-number;
while (number>0) {
if (number%10==countNumber) {
count++;
}
number/=10;
}
return count;
}
int main() {
int number;
scanf("%d",&number);
printf("%d\n",countNumber(number, 7));
return 0;
}
听说回答的够长才能够自动采纳
本回答被网友采纳