Counting The Occurrences Of A Character In An Array Algorithm

Princy Prakash
1 min readApr 27, 2023

--

ALGORITHM:

  1. Get the input array of characters, “a[]”.
  2. Get the input character to search, “char”.
  3. Set the initial count of occurrences to 0: “count=0”.
  4. Set the initial result to 0: “result=0”.
  5. Find the length of the array by iterating through the elements of the array until the end is reached. Set “count” to the total number of elements in the array.
  • Set “i” to 0
  • Repeat until the end of the array is reached:
  • Increment “i” by 1
  • Increment “count” by 1

6. Iterate through each element of the array:

  • Set “j” to 0
  • Repeat until the end of the array is reached:
  • If the element at index “j” is equal to the character “char”, increment “result” by 1.
  • Increment “j” by 1

7. Print the number of occurrences of the character in the array.

  • Print “result”.

CONCLUSION:

The Algorithm “Counting The Occurrences Of A Character In An Array” takes an input array of characters and a character to search, and outputs the number of times the given character appears in the array.

FLOWCHART:

--

--

Princy Prakash
Princy Prakash

Written by Princy Prakash

Hi I Am Princy. I recently discovered my passion for programming and excited to get deeper into the world of technologies also in problem-solving

No responses yet