首页 > 其他 > 详细

统计个位数字

时间:2021-07-13 20:30:35      阅读:26      评论:0      收藏:0      [点我收藏+]

本题要求实现一个函数,可统计任一整数中某个位数出现的次数。例如-21252中,2出现了3次,则该函数应该返回3.其中ND都是用户传入的参数。N的值不超过int的范围;D是[0, 9]区间内的个位数。函数须返回ND出现的次数。

#include <stdio.h>

int Count_Digit ( const int N, const int D );

int main()

{ int N, D;

scanf("%d %d", &N, &D);

printf("%d\n", Count_Digit(N, D));

return 0;

}

int Count_Digit(const int N, const int D)
{
int count,temp,x;
x=N;
if(x<0)
x=-x;
do{
temp=x%10;
if(temp==D)
count++;
x=x/10;
}while(x>0);

return count;
}

技术分享图片

 

统计个位数字

原文:https://www.cnblogs.com/2313942750qq/p/15007556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!