Code, Algorithm, Flowchart, Output for finding vowels in string
In this blog we will see the Code, Algorithm, Flowchart, Output for finding vowels and total number of characters in string.
Algorithm :
1] Start
2] Set the count to 0
3] Loop through the string until it reaches a null character
4] Compare each character to the vowels a, e, i, o, u or A, E, I, O, U.
5] If both are equal, increase the count by one.
6] Print the count of each vowel at the end.
7] Stop
Flowchart:
Output :
Enter a string: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Total number of characters: 26
A: 1
E: 1
I: 1
O: 1
U: 1
Code :
#include <stdio.h>
int main() {
char str[100];
int i=0,count = 0;
int A = 0, E = 0, I = 0, O = 0, U = 0;
printf("Enter a string: ");
fgets(str, 10,stdin);
for (int i = 0; str[i] != '\0'; i++) {
count++;
if (str[i] == 'a' || str[i] == 'A') {
A++;
} else if (str[i] == 'e' || str[i] == 'E') {
E++;
} else if (str[i] == 'i' || str[i] == 'I') {
I++;
} else if (str[i] == 'o' || str[i] == 'O') {
O++;
} else if (str[i] == 'u' || str[i] == 'U') {
U++;
}
}
printf("Total number of characters: %d\n", count-1);
printf("A: %d\nE: %d\nI: %d\nO: %d\nU: %d\n", A,E,I,O,U);
return 0 ;
}

Comments
Post a Comment