Jump to content

Count how many vowels and consonants occur in a string: Difference between revisions

(insert →‎Pascal)
Line 1,459:
5 vowels and 13 consonants (distinct)
22 vowels and 31 consonants (total)</pre>
 
=={{header|Pascal}}==
Standard “Unextended” Pascal (ISO standard 7185) does not really know the notion of strings:
<lang pascal>program countHowManyVowelsAndConsonantsOccurInAString(input, output);
 
var
c: char;
vowel, consonant: set of char;
vowelCount, consonantCount: integer;
 
begin
{ initialize variables - - - - - - - - - - - - - - - - - - }
vowel := ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'];
consonant := ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L',
'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y',
'Z', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm',
'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'];
vowelCount := 0;
consonantCount := 0;
{ process - - - - - - - - - - - - - - - - - - - - - - - - - }
while not EOF do
begin
{ input^ refers to the buffer variable's value }
vowelCount := vowelCount + ord(input^ in vowel);
consonantCount := consonantCount + ord(input^ in consonant);
get(input)
end;
{ result - - - - - - - - - - - - - - - - - - - - - - - - - }
writeLn(vowelCount, ' vowels');
writeLn(consonantCount, ' consonants')
end.</lang>
{{in}}
The quick brown fox jumps over the lazy dog.
{{out}}
11 vowels
24 consonants
 
=={{header|Perl}}==
149

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.