Skip to content

Commit 14c71d6

Browse files
Add files via upload
1 parent 7759476 commit 14c71d6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

count-vowels.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Program to count the number of vowels present in a string.
2+
3+
#include <stdio.h>
4+
5+
int main() {
6+
7+
char text[150];
8+
9+
// get input value for text using fgets()
10+
fgets(text, sizeof(text), stdin);
11+
12+
// variable to count number of vowels
13+
int vowels = 0;
14+
15+
// loop to access each character of text
16+
for (int i = 0; text[i] != '\0'; ++i) {
17+
18+
// check if character at ith position is a vowel (lowercase or uppercase)
19+
if (text[i] == 'a' || text[i] == 'A' || text[i] == 'e' || text[i] == 'E' || text[i] == 'i' || text[i] == 'I' || text[i] == 'o' || text[i] == 'O' || text[i] == 'u' || text[i] == 'U') {
20+
vowels++;
21+
}
22+
}
23+
24+
// print the value of vowel
25+
printf("%d", vowels);
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)