Answer:
int vowels(string s){
int count=0;
for(int i=0;s[i]!='\0';i++){
if(s[i]=='a' || s[i]=='e' ||s[i]=='i'||s[i]=='o'||
s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||
s[i]=='O' || s[i]=='U'){
count++;
}
}
return count;
}
Step-by-step explanation:
Create the function with return type int and declare the parameter as a string.
define the variable count for storing the output. Then, take a for loop for traversing each character of the string and if statement for checking the condition of the vowel.
vowel are 'a', 'e', 'i', 'o', 'u' in lower case. we must take care of the upper case as well.
vowel are 'A', 'E', 'I', 'O', 'U' in upper case.
if the condition is true to update the count by 1.
This process continues until the string not empty.
and finally, return the count.