//Program to print the no. of LOWERCASE, UPPERCASE, NUMBERS, SPACES & SYMBOLS in a String
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s; //requesting string
cin>>s;
int l=s.length(); //checking length
int clower=0; //setting counters
int cupper=0;
int csymbol=0;
int cnum=0;
for(int i=0;i<l;i++){ //loop to go through each char in string
if(s[i]>=97 && s[i]<=122){ //for lowercase
clower++;
}
else if(s[i]>=65 && s[i]<=90){ //for uppercase
cupper++;
}
else if(s[i]>=48 && s[i]<=57){ //for numbers
cnum++;
}
else{ //by default Symbol
csymbol++;
}
}
cout<<"Lower Count: "<<clower<<endl; //printing the required data
cout<<"Upper Count: "<<cupper<<endl;
cout<<"Symbol Count: "<<csymbol<<endl;
cout<<"Number Count: "<<cnum<<endl;
return 0;
}
Note: The program is done using ASCII values you can try the other method also. If this program is asked in interviews it is preferable to execute using ASCII values as it leaves a good impression on the interviewer.
0 Comments