注意:回车符是\n;
原理:将字符放入字符数组中,然后在for循环中一个一个的判断是不是数字,是count加一。
#include<stdio.h>
int main()
{
char ch[100];
int i=0;
for(i;;i++)
{
scanf("%c",&ch[i]);
if(ch[i]=='\n')
break;
}
int count=0;
for(int k=0;k<i;k++)
{
if(ch[k]>='0'&&ch[k]<='9')
count++;
}
printf("%d",count);
return 0;
}
测试结果:
12abrt12@2013
8
--------------------------------
Process exited after 27.76 seconds with return value 0
请按任意键继续. . .