How to resolve the algorithm Letter frequency step by step in the PL/I programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Letter frequency step by step in the PL/I programming language
Table of Contents
Problem Statement
Open a text file and count the occurrences of each letter. Some of these programs count all characters (including punctuation), but some only count letters A to Z.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Letter frequency step by step in the PL/I programming language
Source code in the pl/i programming language
frequencies: procedure options (main);
declare tallies(26) fixed binary static initial ((26) 0);
declare alphabet character (26) static initial
('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
declare c character (1), i fixed binary;
declare in file;
open file (in) title ('/LETTER.DAT,type(text),recsize(200)') input;
on endfile (in) go to prepare_list;
do while('1'b);
get file (in) edit (c) (a(1)); put edit (c) (a);
i = index(alphabet, c);
if i > 0 then tallies(i) = tallies(i) + 1;
end;
prepare_list:
put skip list('Letter', 'Frequency');
do i = 1 to 26;
if tallies(i) > 0 then
put skip list (substr(alphabet, i, 1), tallies(i));
end;
end frequencies;
You may also check:How to resolve the algorithm Handle a signal step by step in the OCaml programming language
You may also check:How to resolve the algorithm Tokenize a string with escaping step by step in the Rust programming language
You may also check:How to resolve the algorithm Main step of GOST 28147-89 step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Y combinator step by step in the BlitzMax programming language
You may also check:How to resolve the algorithm SHA-256 step by step in the NewLISP programming language