C语言统计字符串中数字出现的次数

  • Post author:
  • Post category:其他

对于给定的一个字符串,统计其中数字字符出现的次数。

#include<stdio.h>
int main(void)
{
    /*********Begin*********/
       char s[100];
	   int n;
	   scanf("%d",&n);
	   while(n--)
	   {
	       int count=0;
		   scanf("%s",s);
	       for(int i=0;s[i]!='\0';i++)
	       {
               if(s[i]>='0'&& s[i]<='9') count=count+1;
	       }
		   printf("%d\n",count);
	   }
    /*********End**********/
    return 0;
}

版权声明:本文为xiaotao2333333原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。