int Count_Digit ( const int N, const int D ){
if(N==D)
{
return 1;
}//考虑N=D=0的情况,但是当N、D同为个位数是返回值仍然是1,所以直接用判断条件N=D
int count=0;
int n;
if(N>=0)
n=N;
else
n=-N;
while(n>0){
if(n%10==D){
count++;
}
n/=10;
}
return count;
if(N==D)
{
return 1;
}//考虑N=D=0的情况,但是当N、D同为个位数是返回值仍然是1,所以直接用判断条件N=D
int count=0;
int n;
if(N>=0)
n=N;
else
n=-N;
while(n>0){
if(n%10==D){
count++;
}
n/=10;
}
return count;
}
考虑时忽略了N=D=0的情况。。。
本文介绍了一个名为intCount_Digit的C/C++函数,该函数用于计算整数N中特定数字D出现的次数。文章提供了函数的具体实现,并讨论了特殊情况如N=D=0时的处理。
5712





