Count how many vowels and consonants occur in a string: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
(Count how many vowels and consonants occur in a string en FreeBASIC) |
||
Line 295: | Line 295: | ||
-> H{ { "other" 16 } { "consonant" 31 } { "vowel" 22 } } |
-> H{ { "other" 16 } { "consonant" 31 } { "vowel" 22 } } |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic> |
|||
Dim As String cadena = """Forever the FreeBASIC programming language""" |
|||
Dim As Integer vocal = 0, consonante = 0 |
|||
Function isVowel (Byval n As String) As Boolean |
|||
Select Case Asc(n) |
|||
Case 97, 65, 101, 69, 105, 73, 111, 79, 117, 85 'aAeEiIoOuU |
|||
Return True |
|||
Case Else |
|||
Return False |
|||
End Select |
|||
End Function |
|||
Function isConsonant (Byval c As String) As Boolean |
|||
Dim As Boolean bool1, bool2, bool3 |
|||
bool1 = Not isvowel(c) |
|||
bool2 = (Asc(c) > 64 And Asc(c) < 91) |
|||
bool3 = (Asc(c) > 96 And Asc(c) < 123) |
|||
If bool1 And (bool2 Or bool3) Then |
|||
Return True |
|||
Else |
|||
Return False |
|||
End If |
|||
End Function |
|||
For n As Integer = 1 To Len(cadena) |
|||
Dim As String letra = Mid(cadena,n,1) |
|||
If isVowel(letra) Then vocal += 1 |
|||
If isConsonant(letra) Then consonante += 1 |
|||
Next n |
|||
Print "Input string = "; cadena |
|||
Print "In string occur"; vocal; " vowels" |
|||
Print "In string occur"; consonante; " consonants" |
|||
Sleep</lang> |
|||
{{out}} |
|||
<pre> |
|||
Input string = "Forever the FreeBASIC programming language" |
|||
In string occur 15 vowels |
|||
In string occur 23 consonants |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |