C Program to Find Minimum Occurring Character in a string

C Program to Find Minimum Occurring Character in a string

C program to find the minimum occurring characters in a string; Through this tutorial, we will learn how to find the minimum or lowest occurring characters in a string using the for loop and function in c programs.

Programs to Find Minimum Occurring Character in a string in C

To find the minimum or lowest occurring characters in a string using the for loop and function in c programs:

  • C Program to Find Minimum Occurring Character in a string using For Loop
  • C Program to Find Minimum Occurring Character in a string using Function

C Program to Find Minimum Occurring Character in a string using For Loop

#include <stdio.h>
#include <string.h>
 
int main()
{
  	char str[100], result;
  	int i, len;
  	int min = 0;
  	
  	int freq[256] = {0}; 
 
  	printf("\n Please Enter any String :  ");
  	gets(str);
  	
  	len = strlen(str);
  	
  	for(i = 0; i < len; i++)
  	{
  		freq[str[i]]++;
	}
  		
  	for(i = 0; i < 256; i++)
  	{
		if(freq[i] != 0)
		{
			if(freq[min] == 0 || freq[i] < freq[min])
			{
				min = i;
			}
		}
	}
	printf("\n Character '%c' appears Minimum of %d Times in a Given String :  %s ", min, freq[min], str);
		
  	return 0;
}

The Output of the above c program; as follows:

Please Enter any String :  hello c programmer
Character 'a' appears Minimum of 1 Times in a Given String :  hello c programmer 

C Program to Find Minimum Occurring Character in a string using Function

/* C Program to Find the Minimum Occurring Character in a String */
 
#include <stdio.h>
#include <string.h>

void Min_Occurring(char *str);
 
int main()
{
  	char str[100];
 
  	printf("\n Please Enter any String :  ");
  	gets(str);
  	
  	Min_Occurring(str);
	
  	return 0;
}

void Min_Occurring(char *str)
{
	int i;
  	int min = 0;
  	
  	int freq[256] = {0}; 
  	 	 	
  	for(i = 0; str[i] != '
/* C Program to Find the Minimum Occurring Character in a String */
#include <stdio.h>
#include <string.h>
void Min_Occurring(char *str);
int main()
{
char str[100];
printf("\n Please Enter any String :  ");
gets(str);
Min_Occurring(str);
return 0;
}
void Min_Occurring(char *str)
{
int i;
int min = 0;
int freq[256] = {0}; 
for(i = 0; str[i] != '\0'; i++)
{
freq[str[i]]++;
}
for(i = 0; i < 256; i++)
{
if(freq[i] != 0)
{
if(freq[min] == 0 || freq[i] < freq[min])
{
min = i;
}
}
}
printf("\n Character '%c' appears Minimum of %d Times in a Given String :  %s ", min, freq[min], str);
}
'; i++) { freq[str[i]]++; } for(i = 0; i < 256; i++) { if(freq[i] != 0) { if(freq[min] == 0 || freq[i] < freq[min]) { min = i; } } } printf("\n Character '%c' appears Minimum of %d Times in a Given String : %s ", min, freq[min], str); }

The Output of the above c program; as follows:

Please Enter any String :  welcome to c programming tutorials
Character 'n' appears Minimum of 1 Times in a Given String :  welcome to c programming tutorials 

Recommended C Programs

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *