C语言题目11
//输入一串字符串,以回车结束,统计其中的英文字符、数字字符、空格和其他字符数目;
#include<stdio.h>
int main()
{
char c;
int chars = 0;
int numbers = 0;
int spaces = 0;
int others = 0;
printf("请输入一个字符串,输入完成后敲击回车:");
while(1)
{
c = getchar();
if(c=='\n')
{
break;
}
else
{
if(c>='0' && c<='9')
{
numbers++;
}
else if((c>='a' && c<='z')||(c>='A' && c<='Z'))
{
chars++;
}
else if(c == ' ')
{
spaces++;
}
else
{
others++;
}
}
}
printf("char=%d\tnumber=%d\tspace=%d\tother=%d\n", chars, numbers, spaces, others);
return 0;
}
C语言题目1
//用C编写程序:输入一串字符,计算其中的字符、数字、其他字符的个数并输出。
#include<stdio.h>
int main()
{
char c;
int chars = 0;
int numbers = 0;
int others = 0;
printf("请输入一个字符串,输入完成后敲击回车:");
while(1)
{
c = getchar();
if(c=='\n')
{
break;
}
else
{
if(c>='0' && c<='9')
{
numbers++;
}
else if((c>='a' && c<='z')||(c>='A' && c<='Z'))
{
chars++;
}
else
{
others++;
}
}
}
printf("char=%d\tnumber=%d\tother=%d\n", chars, numbers, others);
return 0;
}