天天看點

統計字元串中26個英文字母的個數

統計字元串中26個英文字母的個數

#include"stdio.h"
int main()
{
	//統計字元串中26個英文字母的個數
	printf("請輸入要統計的字元串:");
	char ch = 0;
	int num = 0;
	while ((ch = getchar()) != '\n')//從緩沖區中一個一個讀
	{
		if (ch >='a'&& ch<='z' || ch>='A'&& ch <= 'Z')
			num++;
	}
	printf("英文字元的個數為:%d\n", num);
	return 0;
}
           

繼續閱讀