int Count_Digit ( const int N, const int D )
{
int n,i,b=0;
n=N;
if(n<0)
{
n=-n;
}
do{
i=n%10;
if(i==D)
b++;
n/=10;
}while(n>0); //记住这里有分号
return b;
}
上面代码为正确代码,必须用do while语句,否则报错,错误在下面:
int Count_Digit ( const int N, const int D )
{
int n,i,b=0;
n=N;
if(n<0)
{
n=-n;
}
while(n>0)
{
i=n%10;
if(i==D)
{
b++;
}
n/=10;
}
return b;
}
用while报错图片:
标签:10,Digit,const,int,个位数,while,报错,统计 From: https://www.cnblogs.com/wwacwing/p/16816247.html