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

我才刚学C,刚到达for,do while之类语句的程度。

希望不要给太复杂的。。谢谢。》
最新回答
心境心清心晴

2024-06-02 03:31:04

#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);
}
浮生远离

2024-06-02 03:48:23

#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;
}
思乔香沁雪

2024-06-02 01:53:12

#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;
}
冰依湄凌

2024-06-02 03:39:51

#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;
}