字符串输出数字

 

 

参考答案:

#include<cstdio>
#include<cstring>
#include<cstdlib>
char a[1000];
int main()
 {
 unsigned int i, count = 0;   //定义无符号int值
   gets_s(a);
  for (i = 0; i <= strlen(a) - 1; i++) //计算字符长度
  if (a[i] >= '0'&&a[i] <= '9')
   count++;
  printf("%d", count);
  system("pause");
   return 0;
 }

 

发表评论

邮箱地址不会被公开。 必填项已用*标注

7 + 8 =