#不知道怎么用函数解决这个题目
本题要求定义一个西数,实现统计任一整数中某个数字出现的次数。
函数原型如下:
int CountDigit(intn. fnt ):1统计数字d在報数n中出现的次数并返回
只需要函数定义部分
输入两个整数n,d(n是int类型范围, 0≤=d<=9)输出一个整数数,为数字d在整数n中出现的次数。
#这个是我自己用c语言写的
int CountDigit(int n, int d)
{
int c = 0;
while (n)
{
if (n % 10 == d)
c++;
n /= 10;
}
return c;
}
int main()
{
int n, d;
while (~scanf("%d%d", &n, &d))
{
printf("%d\n", CountDigit(n, d));
}
return 0;
}