Advertisement

In this program, You will learn how to count number of uppercase, lowercase, whitespaces and special symbol in C++.

```
[email protected]#343 C++
Total number of uppercase alphabets =2
Total number of lowercase alphabets =3
Total number of digits =3
Total number of white spaces =1
Total number of special symbols =4
```

```
#include<iostream>
using namespace std;
int main() {
char a[100];
int i = 0, up = 0, lo = 0;
int dig = 0, spc = 0, sym = 0;
cout << "Enter string:";
cin.getline(a, 100);
while (a[i] != '\0') {
i++;
}
for (int j = 0; j < i; j++) {
if (a[j] >= 65 && a[j] <= 90) {
up++;
} else if (a[j] >= 97 && a[j] <= 122) {
lo++;
} else if (a[j] >= 48 && a[j] <= 57) {
dig++;
} else if (a[j] == 32) {
spc++;
} else {
sym++;
}
}
cout << "Uppercase:" << up;
cout << "\nLowercase:" << lo;
cout << "\nDigits:" << dig;
cout << "\nWhite spaces:" << spc;
cout << "\nSpecial symbols:" << sym;
return 0;
}
```

```
Enter string:Xiith #34
Uppercase:1
Lowercase:4
Digits:2
White spaces:1
Special symbols:1
```