输入一行字符,分别统计出其中大写字母,小写字母,数字的个数
4个回答
展开全部
#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);
}
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);
}
展开全部
#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;
}
#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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
}
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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
}
#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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询