Consider an array, letters, that contains elements made up of only single letter
ID: 3835684 • Letter: C
Question
Consider an array, letters, that contains elements made up of only single letters (either uppercase or lowercase). Determine the total number of vowels and the total number of consonants (assume y is a consonant). Output the number of vowels and the number of consonants. You may assume that the array only contains letters, though the letters may be uppercase and lowercase. vowels = 0; consonants = 0; letters {'t', 'o', 'd', 'a', 'y, 'l', 's', t', 'e', 's', 't', 't', 'h', 'r', 'e', 'e', ...}; An array grades contains percentages of test grades. Populate a corresponding letterGrades array with the letter grade: grades = [89, 80, 69, 99, 75, ....., 69, 90] letterGrades = [];Explanation / Answer
vowels = 0;
consonants = 0;
letters = ['t', 'o', 'd', 'a', 'y', 'l', 's', 't', 'e', 's', 't', 'h', 'r', 'e', 'e'];
len = size(letters, 2);
for i = 1: len
if (letters(i) == 'a' || letters(i) == 'A' ||
letters(i) == 'e' || letters(i) == 'E' ||
letters(i) == 'i' || letters(i) == 'I' ||
letters(i) == 'o' || letters(i) == 'O' ||
letters(i) == 'u' || letters(i) == 'U')
vowels = vowels + 1;
else
consonants = consonants + 1;
end
end
fprintf('Number of vowels %d ', vowels);
fprintf('Number of consonants %d ', consonants);