Question

2) Write a Pascal program to do the following for matrix A of size 20x20 (its elements are characters of English alphabet (up

The non English parts of the question it's just translation.Please answer. I will give thumbs up

0 0
Add a comment Improve this question Transcribed image text
Answer #1

To solve this problem we take a 2D array Matrix 20x20, an alpha array that contains all the small and capital letters in it.

And a freq array to record the frequency of each letter.

Then we scan the Matrix array one letter at a time. And see the position of that letter in alpha array and incrementing the value at that position in the freq array.

For eg, current element scanned in Matrix is 'k', then the position of 'k' in alpha is 11. So, freq[11] will be incremented implying that one 'k' is found in Matrix.  

CODE:

program Alphabet;

uses
SysUtils;
var
i: Integer;
j: Integer;
k: Integer;
alpha: String;
Matrix: array[1..20, 1..20] of char;
freq : array[1..52] of Integer;
begin
Randomize;
  
alpha:='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for k := 1 to 52 do
freq[k] := 0; //initializing frequency of each letter to 0
for i := 1 to 20 do
for j := 1 to 20 do
Matrix[i, j] := alpha[Random(53)]; //53 = 26(small)+26(capital)+1
for i := 1 to 20 do
begin
for j := 1 to 20 do
Write(Matrix[i, j], ' ');
WriteLn;
end;
  
for i := 1 to 20 do
begin
for j := 1 to 20 do
begin
for k:=1 to 52 do
if Matrix[i,j] = alpha[k] then //if letter found
freq[k]:= freq[k]+1; // then increment frequency of that letter
end;   
end;
WriteLn;
  
//printing the alphabet and its frequency:
for k := 1 to 52 do
begin
Write(alpha[k],' : ',freq[k]);
WriteLn;
end;

end.

OUTPUT:

forget -T? /usr/bin/id.bfd: warning: link.res contains output sections; did you MmoqnO Y zi d E F G Z n KEY b t zo Vdmx Deoj

a : 5 b: 6 с 4 d : 7 (D 4 f 4 g : 10 h : 5 i : 10 5 j: k : 1 : 3 11 m 9 n : 5 o : 11 Ip: 4 q: ол r . 8 S . 5 t : 8 u 1 V 9 3

: 8 N A : 12 B: 11 C: 11 D : 7 E : 8 F : 5 G : 9 H : 3 I : 7 15 K : 9 L : 9 M : 14 N : 7 O : 4 IP .. 13 12 R: 7 S 5 T 7 U : 8

Add a comment
Know the answer?
Add Answer to:
The non English parts of the question it's just translation.Please answer. I will give thumbs up...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT