Tuesday 24 June 2014

C++ program to count the number of upper-case and lower-case characters in a string


Here is a C++ program to count the number of upper-case and lower-case characters in a string


 SOURCE CODE OUTPUT
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str[300];
    int i,nlrcse=0,nupcse=0;
    cout<<"Enter String : ";
    cin.getline(str,300);
    for(i=0;str[i]!='\0';i++)
    {
        if(str[i]>=65&&str[i]<=90)
            nupcse++;
        else if(str[i]>=97&&str[i]<=122)
            nlrcse++;
    }
    cout<<"Number of Uppercase characters : "<<nupcse<<endl;
    cout<<"Number of Lowercase characters : "<<nlrcse;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment