C语言(简单的)编写程序输入任意一串字符统计其中大写字母,小写字母。数字及其他字符的个数

 我来答
百度网友6fa3859
2016-01-09 · TA获得超过3348个赞
知道小有建树答主
回答量:1148
采纳率:85%
帮助的人:385万
展开全部

程序可按照以下流程执行:

    1、输入字符串

    2、对于字符串中的每一个字符,判断其为何种类型,并将相应的累加计数器加1。对于大小写字母和数字,可通过一个范围(大于等于某值和小于等于某值)来判断

代码如下:

#include <string.h>
#include <stdio.h>

int main()
{
char str[1000];
int lowAlpha, upAlpha, num, other;
int i;

lowAlpha = upAlpha = num = other = 0;
for (i = 0; i < strlen(str); i++)
if (str[i] >= 'a' && str[i] <= 'z')
lowAlpha++;
else if (str[i] >= 'A' && str[i] <= 'Z')
upAlpha++;
else if (str[i] >= '0' && str[i] <= '9')
num++;
else
other++;

printf("Upper:%d, Lower:%d, Number:%d, Other:%d\n", upAlpha, lowAlpha, num, other);

return 0;
}
匿名用户
推荐于2017-11-26
展开全部
#include<stdio.h>
#include<string.h>
#define n 20 //你可以改变n的值,但要保证n至少大于你想输入的字符数目一位
void main()
{
int i,BC,lc,m; //BC为大写的字母,lc为小写的字母
char a[n];
i=BC=lc=m=0;
printf("输入字符串,以#号结束:\t");
gets(a);
while(a[i]!='\0')
{
if(a[i]>='A'&&a[i]<='Z') BC++;
else
if(a[i]>='a'&&a[i]<='z') lc++;
else
m++;
i++;
}
printf("大写字母个数为:%d\n",BC);
printf("小写字母个数为:%d\n",lc);
printf("其他字符个数为:%d\n",m);
}
我调试通过了的
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-10-22
展开全部
#include <stdio.h>
void count(char*);
int main()
{
char ch[100]={0};
scanf("%s", ch);
count(ch);
return 0;
}

void count(char* ch)
{
//分别记录大写,小写,数字的个数。
int big=0, small=0, character=0,qita = 0;
while (*ch)
{
if ((*ch>='A')&&(*ch<='Z'))
{
++big;
}
else if ((*ch>='a')&&(*ch<='z'))
{
++small;
}
else if ((*ch>='0')&&(*ch<='9'))
{
++character;
}
else
{
++qita;
}
++ch;
}
printf("大写字母的个数是:%d\n", big);
printf("小写字母的个数是:%d\n", small);
printf("数字的个数是:%d\n", character);
printf("其他字符的个数是:%d\n", qita);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式