-3

Please. .kindly help me on this problem. .

Output:

Enter string: already

A - 2

B - 0

C - 0

D - 1

E - 1

rkhb
  • 14,159
  • 7
  • 32
  • 60

2 Answers2

1

Depending on the language you're supporting (read: not all languages that use 'A' to 'E' have the same number of chars), create an array of unsigned values (the data type is also depending on the longest plausible size of an array), then enumerate from the start of the given alphabet to the end, counting the discoveries and incrementing the assigned array entry.
For completeness: You didn't call out if the case counts (read: is 'a' to be counted as 'A')... if they are to be counted separately, you'll need to preserve a suitable storage for the varied cases. Once the alphabet has been enumerated, simply walk from the beginning of the array to the end, dumping the discoveries. It's not the most elegant solution... but does meet the provided parameters.

Brycej
  • 64
  • 3
1

Write a procedure that loops over the entire string in search of a specific character. For each match increment a counter. Upon return display the result as character DL occurs DH times:
e.g. "A - 2".

mov  dl, "A"
call CountChar
... print result ...
mov  dl, "B"
call CountChar
... print result ...


CountChar:
  mov  dh, 0
  mov  cx, ... length of the input string ...
  jcxz Ready
  mov  bx, ... address of the input string ...
 Again:
  cmp  [bx], dl
  jne  Skip
  inc  dh
 Skip:
  inc  bx
  loop Again
 Ready:
  ret
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • This question wants counts for the first 5 letters of the alphabet. A range-check and a histogram (`inc byte [counters + bx]` or something) would only need one pass over the string, and probably be more efficient than counting each of the 5 letters separately. As for static code size, probably pretty similar since this count loop can be reused inside an outer loop over `dl` from `"A"` to `"E"`, perhaps favouring this since you don't need space for an array or a separate loop over the results. – Peter Cordes Jan 23 '23 at 14:33