帮助:C语言题目

来源:百度知道 编辑:UC知道 时间:2024/05/08 13:33:52
输入50个字符,统计字母,数字及其它字符的个数。

#include<stdio.h>

int main()
{
int i;
char a[50];
int number=0; //数字的数目
int letter=0; //字母的数目
int other=0; //其他符号的数目
for(i=0; i<=49; i++)
{
scanf("%c",&a[i]);
if((a[i]>='a'&&a[i]<='z') || (a[i]>='A'&&a[i]<='Z'))
letter++;
else if(a[i]>='0'&&a[i]<='9')
number++;
else
other++;
}
printf("%d,%d,%d",letter,number,other);
return 0;
}

#include<stdio.h>
#include<string.h>
void main()
{
char s[1024];
int num=0,low=0,up=0,spa=0,other=0;
gets(s);
for(int i=0;i<(int)strlen(s);i++)
{
char c = s[i];
if(c == ' ')
{
spa++;
}
else if(c >= 'a' && c <= 'z')
{
low++;
}
else if(c >= 'A' && c <= 'Z')