C Program to find minimum occurrence of character in a string

CServer Side ProgrammingProgramming

An array of characters is called a string.


Following is the declaration for declaring an array is as follows −

char stringname [size];

For example − char string[50]; string of length 50 characters


  • Using single character constant −
char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}
  • Using string constants −
char string[10] = "Hello":;

Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.

Finding minimum occurrence

The logic to find minimum occurrence of a character in a given string is as follows −

for(i=0; i<CHARS; i++){
      if(frequency[minimum] == 0 || frequency[i]< fequency[minimum]) minimum = i;


Following is the C program to find minimum occurring character in a string.

#define SIZE 100 // Maximum string size
#define CHARS 255 // Maximum characters allowed
int main(){
   char string[SIZE];
   int frequency[CHARS];
   int i = 0, minimum;
   int value;
   printf("Enter the string:\n ");
   for(i=0; i<CHARS; i++){
      frequency[i] = 0; // initialize freq of all char to zero
   while(string[i] != '\0'){ // finding freq of each char
      value = (int)string[i];
      frequency[value] += 1;
   minimum = 0;
   for(i=0; i<CHARS; i++){// finding min freq
         if(frequency[minimum] == 0 || frequency[i]<fequency[minimum])
            minimum = i;
   printf("Minimum occurrence character is '%c' = %d times.", minimum,    frequency[minimum]);
   return 0;


When the above program is executed, it produces the following result −

Enter the string:
Minimum occurrence character is 'a' = 1 times.
Updated on 24-Mar-2021 14:12:33