求C语言一题:数字统计
答案:2 悬赏:50
解决时间 2021-01-29 19:39
- 提问者网友:我一贱你就笑
- 2021-01-29 13:06
求C语言一题:数字统计
最佳答案
- 二级知识专家网友:几近狂妄
- 2021-01-29 14:14
while (a[i] != 0)后面多了个分号……于是无限循环……
还有,不需要a这个数组,声明成一个普通变量就行了。j是多余的变量。
还有,不需要a这个数组,声明成一个普通变量就行了。j是多余的变量。
全部回答
- 1楼网友:酒醒三更
- 2021-01-29 14:33
#include
int times(int to_handle);
int main(void)
{
int n=0,m=0;
//[n,m]
int sum=0;
scanf("%d %d",&n, &m);
while(n>m)
{
scanf("%d %d",&n, &m);
}
for(;n<=m;n++)
{
sum += times(n);
}
printf("%d ",sum);
return 0;
}
int times(int to_handle)
{
char buff[1024]={0};
sprintf(buff, "%d", to_handle);
char *ptr = buff;
int count=0;
while(*ptr)
{
if(*ptr == '2')
++count;
ptr++;
}
return count;
}
int times(int to_handle);
int main(void)
{
int n=0,m=0;
//[n,m]
int sum=0;
scanf("%d %d",&n, &m);
while(n>m)
{
scanf("%d %d",&n, &m);
}
for(;n<=m;n++)
{
sum += times(n);
}
printf("%d ",sum);
return 0;
}
int times(int to_handle)
{
char buff[1024]={0};
sprintf(buff, "%d", to_handle);
char *ptr = buff;
int count=0;
while(*ptr)
{
if(*ptr == '2')
++count;
ptr++;
}
return count;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯