第十三周项目五 字符串操作(统计大/小写字母个数)

来源:互联网 发布:淘宝链接微信打不开 编辑:程序博客网 时间:2024/05/18 03:05

大写字母统计

问题及代码:

#include<iostream>#include<cstdio>using namespace std;int main(){ char str[50]; int i=0,n=0; cout<<"输入字符串:"; gets(str); while(str[i]!='\0') {  if(str[i]>=65 && str[i]<=90) n++;//ASC码值中065~090代表大写字母A~Z  i++; } cout<<"其中的大写字母个数是: "<<n<<endl; return 0;}

运行结果:



小写字母统计

问题及代码:

#include<iostream>#include<cstdio>using namespace std;int main(){ char str[50]; int i=0,n=0; cout<<"输入字符串:"; gets(str); while(str[i]!='\0') {  if(str[i]>=97 && str[i]<=122) n++;//ASC码值中097~122代表小写字母a~z  i++; } cout<<"其中的小写字母个数是: "<<n<<endl; return 0;}

运行结果:


0 0
原创粉丝点击