输入一行字符,分别统计出其中大写字母,小写字母,数字的个数

我才刚学C,刚到达for,dowhile之类语句的程度。希望不要给太复杂的。。谢谢。》... 我才刚学C,刚到达for,do while之类语句的程度。

希望不要给太复杂的。。谢谢。》
展开
 我来答
return8023
推荐于2017-09-04 · TA获得超过527个赞
知道小有建树答主
回答量:251
采纳率:100%
帮助的人:294万
展开全部
#include <stdio.h>
void main()
{
int a = 0, b = 0, c = 0;
int i = 0;
char d[50] = "";
scanf("%s", d);
while(d[i] != '\0')
{
if(d[i] >= 65 && d[i] <= 90)
a++;
else if(d[i] >=97 && d[i] <= 122)
b++;
else if(d[i] >= 48 && d[i] <= 57)
c++;
i++;
}
printf("大写字母:%d 小写字母%d 数字%d\n", a, b, c);
}
百度网友a0622aeba
2009-04-05 · TA获得超过1703个赞
知道小有建树答主
回答量:1145
采纳率:0%
帮助的人:1564万
展开全部
#include <stdio.h>
#include <stdlib.h>
int main()
{
int little=0,large=0,num=0;
char ch;
ch=getchar();
while(ch!='\n')
{
if(ch>='A'&&ch<='Z')large++;
else if(ch>='a' && ch<='z')little++;
else if(ch>='0'&&ch<='9')num++;
ch=getchar();
}
printf("大写:%d\n小写:%d\n数字:%d\n",large,little,num);
system("pause");
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
boyue163
2009-04-05 · TA获得超过7643个赞
知道小有建树答主
回答量:662
采纳率:0%
帮助的人:279万
展开全部
#include <iostream>
using namespace std;
int main()
{
char c;
int lettersmall=0,letterbig=0, digit=0;
cout<<"please enter one line:"<<endl;
while((c=getchar())!='\n') //当输入不是空格
{
if(c>='a'&&c<='z') //小写
lettersmall++;
else if(c>='A'&&c<='Z') //大写
letterbig++;
else if(c>='0'&&c<='9') //数字
digit++;
}
cout<<"lettersmall:"<<lettersmall<<",letterbig:"<<letterbig<<",digit:"<<digit<<endl;
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
宛穹北飞荷
2019-06-12 · TA获得超过3755个赞
知道小有建树答主
回答量:3141
采纳率:31%
帮助的人:186万
展开全部
#include<iostream>
#include<cstring>
using
namespace
std;
void
main()
{
char
str[100];
int
count1=0,count2=0,count3=0;
cout<<"input
the
string:"<<endl;
cin>>str;
int
size=strlen(str);
int
i=0;
while(i<size)
{
if(str[i]>='a'&&str[i]<='z')
count1++;
if(str[i]>='A'&&str[i]<='Z')
count2++;
if(str[i]>='0'&&str[i]<='9')
count3++;
i++;
}
cout<<"the
stirng
has
lowercase
letter's
amount:
"<<count1<<endl;
cout<<"the
stirng
has
capital
letter's
amount:
"<<count2<<endl;
cout<<"the
stirng
has
digital
letter's
amount:
"<<count3<<endl;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式