Exercise 3-4 Statistics character (15point (s)). C

This question requires programming, enter 10 characters, count the number of letters, spaces, or carriage return, numeric characters, and other characters in them.

Input formats:
input is 10 characters. Finally, a carriage return represents the input end, is not included.

Output format:
Following the one line

letter = number of letters, blank = the number of spaces or carriage returns, digit = number of numeric characters, other = number of characters other

Output format.

Sample input:
aZ &
09 Az

Output Sample:
Letter =. 4, blank =. 3, digit for = 2, OTHER. 1 =
Why IS My code Wrong !!?
Here Insert Picture Description

//   Date:2020/3/17
//   Author:xiezhg5
#include <stdio.h>
int main(void)
{
	int i;
	char c;
	int letter=0,blank=0,digit=0,other=0;
	for(i=1;i<=10;i++)
	{
		c=getchar();
		if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
			letter++;
		else if(c==' '||c=='\n')
			blank++;
		else if(c>='0'&&c<='9')
			digit++;
		else
			other++;
	}
	printf("letter = %d, blank= %d, digit = %d, other = %d\n",letter,blank,digit,other);
	return 0;
}
Published 65 original articles · won praise 28 · views 1748

Guess you like

Origin blog.csdn.net/qq_45645641/article/details/104923876