Count how many vowels and consonants occur in a string: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Modula-2) |
Not a robot (talk | contribs) (Add BCPL) |
||
Line 168: | Line 168: | ||
69 characters, 22 vowels, 31 consonants, 16 other |
69 characters, 22 vowels, 31 consonants, 16 other |
||
</pre> |
</pre> |
||
=={{header|BCPL}}== |
|||
<lang bcpl>get "libhdr" |
|||
let ucase(c) = |
|||
'a' <= c <= 'z' -> c - 32, |
|||
c |
|||
let letter(c) = 'A' <= ucase(c) <= 'Z' |
|||
let vowel(c) = |
|||
ucase(c) = 'A' | |
|||
ucase(c) = 'E' | |
|||
ucase(c) = 'I' | |
|||
ucase(c) = 'O' | |
|||
ucase(c) = 'U' |
|||
let consonant(c) = letter(c) & ~vowel(c) |
|||
let count(p, s) = valof |
|||
$( let total = 0 |
|||
for i = 1 to s%0 |
|||
if p(s%i) then total := total + 1 |
|||
resultis total |
|||
$) |
|||
let example(s) be |
|||
$( let v = count(vowel,s) |
|||
let c = count(consonant,s) |
|||
writef("'%S': %N vowels, %N consonants.*N", s, v, c) |
|||
$) |
|||
let start() be |
|||
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|C}}== |
=={{header|C}}== |