Skip to content

Commit 24a65aa

Browse files
committed
renamed: from string/q1
1 parent ad7bbbc commit 24a65aa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//WAP to count the number of vowels and consonants in a given text.
2+
3+
#include <ctype.h>
4+
#include <stdio.h>
5+
#include <string.h>
6+
7+
int main() {
8+
char str[51];
9+
int c = 0, c2 = 0; // c- is incremented when vowels are found, c2 is incremented when consonants are found
10+
printf("Enter the string: ");
11+
scanf("%s", str);
12+
for (int i = 0; i < strlen(str); i++) {
13+
char ch = tolower(str[i]);
14+
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
15+
c++;
16+
} else {
17+
c2++;
18+
}
19+
}
20+
printf("Number of\n vowels: %d \n Consonants: %d\n", c, c2);
21+
return 0;
22+
}

0 commit comments

Comments
 (0)