C++ 输入一行字符,分别统计出其中英文字母个数

来源:百度知道 编辑:UC知道 时间:2024/05/17 07:27:01
#include<stdio.h>
void main()
{
int letter=0,num=0,blanks=0,others=0;
char c;
while((c=getchar())!='\n')
{
if(c>='A'&&c<='Z'||c>='a'&&c<='b')
letter=letter++ ;
else if(c>=0||c<=9);
num=num++;
else if(c==' ');
blanks=blanks++;
else
others=others++;
}
printf("the lerrers are%d,the num are%d,the blanks are%d,the others are%d",letter,num,blanks,others);
}

没什么大错,代码如下:
#include<stdio.h>
void main()
{
int letter=0,num=0,blanks=0,others=0;
char c;
while((c=getchar())!='\n')
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z')
letter++;
else if(c>='0'&&c<='9')//把||改为&&,在就是记住,字符类型赋值要用‘’引起来。
num++;
else if(c==' ')
blanks++;
else
others++;
}
printf("the lerrers are %d\nthe num are %d\nthe blanks are %d\nthe others are %d\n",letter,num,blanks,others);
}
有问题再联系我。

#include<stdio.h>
void main()
{
int letter=0,num=0,blanks=0,others=0;
char c;
while((c=getchar())!='0') //这里以字符‘0’结束
{
if(c>='A'&&c<='Z'||c>='a'&&c<='b')
letter=letter++ ;
else if(c>=0||c<=9)// 去掉后面的分号
num=num++;
else if(c==' ')//去掉后面的分号

C语言 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。 C问题,用FOR语句做:输入一行字符,分别统计其中英文字母,空格,数字和其他字符的个数. 求解:用C.输入一行字符,分别统计出其中英文字母,空格,数字和其它字符的个数 用C语言编程:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数. C语言题:输入一行字符,分别统计出其中的英文字母、空格、数字和其它字符。 输入一行字符,分别统计其中的英文大写字母,小写字母,数字字符和其他字符 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 编程:输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 输入一行字符,分别统计出其中的英文字母.空格.数字.和其他字符的个数!