求一道C语言的编程题
#include "stdio.h"
int main()
{
char s[80]={0};
int i,countA=0,countB=0,countC=0,countD=0,countE=0;
gets(s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]>='A' && s[i]<='Z')
countA++;
else if(s[i]>='a' && s[i]<='z')
{
countB++;
s[i]+='A'-'a';
}
else if(s[i]>='0' && s[i]<='9')
countC++;
else if(s[i]==' ')
countD++;
else
countE++;
}
printf("输入字符串中大写字母数:%d\n",countA);
printf("输入字符串中小写字母数:%d\n",countB);
printf("输入字符串中数字字符数:%d\n",countC);
printf("输入字符串中空格字符数:%d\n",countD);
printf("输入字符串中其它字符数:%d\n",countE);
printf("小写字母转成大写字母后输出为:%s\n",s);
}
{
char s[80] = {0};
int len = 0;
int bNum = 0;
int sNum = 0;
int nNUm = 0;
int spNum = 0;
int i;
printf(" 请输入字符串:\n");
for(i = 0; i < 79; i++)
{
s[i] = getchar();
if (s[i] = '\n')
{
s[i] = '\0';
break;
}
}
len = strlen(s);;
printf("总长度为:%d\n", len);
for (i = 0; i < len; i++)
{
if (s[i] >= 'a' && s[i] <= 'z')
{
sNum++;
s[i] += 'A' - 'a';
}
else if (s[i] >= 'A' && s[i] <= 'Z')
{
bNum++;
}
else if (s[i] >= '0' && s[i] <= '9')
{
nNum++;
}
else if (s[i] == ' ')
{
spNum++;
}
}
printf("大写字母有%d个\n", bNum);
printf("小写字母有%d个\n", sNum);
printf("空格有%d个\n", spNum);
printf("其他字符有%d个\n", len - bNum - sNum - spNum);
printf("%s\n", s);
}
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
char s[80] = {'\0'};
int i, digital = 0, upper_alpha = 0, low_alpha = 0, space = 0, other = 0, length;
gets(s);
length = strlen(s);
for (i = 0; i < length; i++)
{
if (islower(s[i]))
{
low_alpha++;
s[i] = toupper(s[i]);
}
else if (isupper(s[i]))
upper_alpha++;
else if (isdigit(s[i]))
digital++;
else if (isspace(s[i]))
space++;
else
other++;
}
printf("%2d %2d %2d %2d %2d\n", low_alpha, upper_alpha, digital, space, other);
for (i = 0; i < length; i++)
{
printf("%c", s[i]);
}
printf("\n");
return 0;
}