-
Notifications
You must be signed in to change notification settings - Fork 0
/
PAT-2.c
33 lines (32 loc) · 1.03 KB
/
PAT-2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* C program to count the number of vowels, consonants, digits and special characters in a string */
#include <stdio.h>
int main()
{
char str[150];
int i, vowels, consonants, digits, spaces, symbols;
vowels = consonants = digits = spaces = symbols = 0;
gets(str);
for(i=0; str[i]!='\0'; ++i){
if(str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U'){
++vowels;
}
else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z')){
++consonants;
}
else if(str[i]>='0' && str[i]<='9'){
++digits;
}
else if (str[i]==' '){
++spaces;
}
else{
++symbols;
}
}
printf("Vowels: %d",vowels);
printf("\nConsonants: %d",consonants);
printf("\nDigits: %d",digits);
printf("\nWhite spaces: %d", spaces);
printf("\nSymbols: %d", symbols);
return 0;
}