计算大小字符分别出现的次数

来源:互联网 发布:软件开发项目进度 编辑:程序博客网 时间:2024/05/21 07:06
 * Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 作    者:张梦佳* 完成日期:2013 年 12 月2 日* 版 本 号:v1.0** 输入描述:* 问题描述:* 程序输出:计算大小字符分别出现的次数* 问题分析:* 算法设计:*/#include <iostream>#include <cstdio>using namespace std;int main( ){    char str[50];    int i,n=0,l=0;    cout<<"输入字符串:";    gets(str);    for(i=0;str[i]!='\0';i++)    {        if(str[i]>='a'&&str[i]<='z')n++;        if(str[i]>='A'&&str[i]<='Z')l++;    }    cout<<"出现小写字符的个数有"<<n<<endl;    cout<<"出现大写字符的个数有"<<l<<endl;    return 0;}


 

感悟

\0和/0不一样,,要分清

原创粉丝点击