C programming code :
#include <stdio.h>
int main() {
char s[1000];
scanf("%s", s);
int i = 0;
int vowels = 0;
int consonants = 0;
while(s[i++] != '\0') {
if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' )
vowels++;
else
consonants++;
}
printf("%d",vowels);
return 0;
}Python code:
def vowel_count(str):
count = 0
vowel = "aeiouAEIOU"
for alphabet in str:
if alphabet in vowel:
count = count + 1
print(count, end='')
str = input()
vowel_count(str)
Java code:
import java.util.Scanner;
public class code1 {
static int isVowel(char ch)
{
ch = Character.toUpperCase(ch);
if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') {
return 1;
}
else return 0;
}
static int countVowels(String str, int n)
{
if (n == 1) {
return isVowel(str.charAt(n - 1));
}
return countVowels(str, n-1) + isVowel(str.charAt(n - 1));
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
System.out.print(countVowels(str,str.length()));
}
}
Comments
Post a Comment