Mar 5, 2007

C++ Program to count uppercase, lower case and numbers in given string

C++ program to count upper case, lower case and numbers in given string. This program will accept a string. then it will count uppercase alphabets(capital letters), small alphabets (lower case letters) and numbers too. Type this in your favourite C++ editor and check it out.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
main()
{
clrscr();
char st[40];
int u,l,d,o,i;
u=i=d=o=l=0;
cout<<"Enter a string maximum 40 characters";
gets(st);
for (i=0;st[i]!='\0';i++)
{
if(st[i]>=65 && st[i]<=90)
u++;
if(st[i]>=97 && st[i]<=122)
l++;
if(st[i]>=48 && st[i]<=57)
d++;
}
cout<<endl<<"The Total upper case characters is : "<<u;
cout<<endl<<"The Total lower case characters is : "<<l;
cout<<endl<<"The Total digit is : "<<d;
getch();
}

No comments:

Post a Comment