Count how many vowels and consonants occur in a string: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add BCPL) |
Not a robot (talk | contribs) (Add Cowgol) |
||
Line 295: | Line 295: | ||
</pre> |
</pre> |
||
=={{header|Cowgol}}== |
|||
<lang cowgol>include "cowgol.coh"; |
|||
sub vowels_consonants(s: [uint8]): (vowels: intptr, consonants: intptr) is |
|||
vowels := 0; |
|||
consonants := 0; |
|||
while [s] != 0 loop |
|||
var ch := [s] | 32; |
|||
if ch >= 'a' and ch <= 'z' then |
|||
if ch == 'a' or ch == 'e' or ch == 'i' |
|||
or ch == 'o' or ch == 'u' then |
|||
vowels := vowels + 1; |
|||
else |
|||
consonants := consonants + 1; |
|||
end if; |
|||
end if; |
|||
s := @next s; |
|||
end loop; |
|||
end sub; |
|||
sub example(s: [uint8]) is |
|||
var vowels: intptr; |
|||
var consonants: intptr; |
|||
(vowels, consonants) := vowels_consonants(s); |
|||
print("'"); |
|||
print(s); |
|||
print("': "); |
|||
print_i32(vowels as uint32); |
|||
print(" vowels, "); |
|||
print_i32(consonants as uint32); |
|||
print(" consonants."); |
|||
print_nl(); |
|||
end sub; |
|||
example("If not now, then when? If not us, then who?");</lang> |
|||
{{out}} |
|||
<pre>'If not now, then when? If not us, then who?': 10 vowels, 20 consonants.</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
Line 308: | Line 348: | ||
seq [(Consonant, 31); (Vowel, 22); (Other, 16)] |
seq [(Consonant, 31); (Vowel, 22); (Other, 16)] |
||
</pre> |
</pre> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-06-02}} |
{{works with|Factor|0.99 2021-06-02}} |