7-2 统计字符串中数字字符的个数

输入一个字符串,统计其中数字字符(‘0’……‘9’)的个数。

输入格式:
输入在一行中给出一个不超过80个字符长度的、以回车结束的非空字符串。

输出格式:
输出所统计的数字字符的个数。

输入样例:
Enter a string: It’s 512?
输出样例:
3
代码:

#include 
int main()
{
     
	char a[81];
	int i=0,out=0;
	while(i < 81)
	{
     
		scanf("%c",&a[i]);
		if(a[i] == '\n')
		break;
		if(a[i] >= '0'&&a[i] <= '9')
		out++;
		i++;	
	}
	printf("%d",out);
	return 0;
 } 

你可能感兴趣的:(c语言,字符串,代码规范)