Write A C++ Program To Count Letters ,Space,Digits,And Others .
#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:
Enter String :
Hiii Iam mohamad contact is 78 42***
letter :-23
digit :-4
space :-6
other :-3
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
Enter String :
Hiii Iam mohamad contact is 78 42***
letter :-23
digit :-4
space :-6
other :-3
need an explanation for this answer? contact us directly to get an explanation for this answer