Jump to content

Letter frequency: Difference between revisions

Added FreeBASIC
(→‎{{header|Julia}}: update to julia version 0.5)
(Added FreeBASIC)
Line 997:
end program LetterFrequency
</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
Dim a(65 to 90) As Integer ' array to hold frequency of each letter, all elements zero initially
Dim fileName As String = "input.txt"
Dim s As String
Dim i As Integer
Open fileName For Input As #1
 
While Not Eof(1)
Line Input #1, s
s = UCase(s)
For i = 0 To Len(s) - 1
a(s[i]) += 1
Next
Wend
 
Close #1
 
Print "The frequency of each letter in the file "; fileName; " is as follows:"
Print
For i = 65 To 90
If a(i) > 0 Then
Print Chr(i); " : "; a(i)
End If
Next
Print
Print "Press any key to quit"
Sleep</lang>
 
{{out}}
<pre>
/'
results for input.txt which contains the single line:
The quick brown fox jumps over the lazy dog.
'/
 
The frequency of each letter in the file input.txt is as follows:
 
A : 1
B : 1
C : 1
D : 1
E : 3
F : 1
G : 1
H : 2
I : 1
J : 1
K : 1
L : 1
M : 1
N : 1
O : 4
P : 1
Q : 1
R : 2
S : 1
T : 2
U : 2
V : 1
W : 1
X : 1
Y : 1
Z : 1
</pre>
 
=={{header|Go}}==
9,492

edits

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