Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program To Check Date Validation (Valid Or Not... >>
<< C++ Program To Find Age Between 40 To 60...