从键盘输入一个不超过20个字符的字符串,存储到一个字符数组中。统计其中数字字符的个数。

如题所述

#include<stdio.h>
main()
{int count=0,i=0;
char s[20];
scanf("%s",s);
while(s[i]!='\0')
{if(s[i]>=48&&s[i]<=57)
count++;
i++;}
printf("数字字符个数为:%d\n",count);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-17
char c;
int counter = 0;
while(cin>>c)
{
if(c>='0' && c<='9')counter++;
}
cout<<counter<<endl;
相似回答