04/11/2015

C++ Program To Count Letters ,Space,Digits,And Others

Problem :- Write A C++ Program To Count Letters ,Space,Digits,And Others .

Logic :- If you Want to Understand This Problem You Need to See This Problem C++ Program To Find ASCII Value Of Any Character Or String .you also Can Modify .

Solution :-

#include<iostream>
#include<string>
using namespace std;
int main()
{
int i,ltr=0,digit=0,sp=0,oth=0;
char ch[50];

cout<<"Enter String :\n";
cin.getline(ch,50);
for(i=0;ch[i]!=0;i++)
{
if((97<=ch[i] && ch[i]<122) || (ch[i]<=90 && ch[i]>=65))
ltr++;
else if(ch[i]>=47 && ch[i]<=57)
digit++;
else if(ch[i]==32)
sp++;
else
oth++;
}
cout<<"letter :-"<<ltr<<"\ndigit :-"<<digit<<"\nspace :-"<<sp<<"\nother :-"<<oth;
return 0;
}

Output:-

C++ Program To Count Letters ,Space,Digits,And Others

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: