C Program to Find Maximum Occurring Character in a string

C Program to Find Maximum Occurring Character in a string

C program to find the maximum occurring characters in a string; Through this tuorial, we will learn how to find the maximum occuring characters in a string using the for loop and function in c programs.

Programs to Find Maximum Occurring Character in a string in C

To find the maximum occuring characters in a string using the for loop and function in c programs:

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

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

/* C Program to Find Maximum Occurring Character in a String */
 
#include <stdio.h>
#include <string.h>
 
int main()
{
  	char str[100], result;
  	int i, len;
  	int max = 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] > freq[max])
		{
			max = i;
		}
	}
	printf("\n Character '%c' appears Maximum of %d Times in a Given String :  %s ", max, freq[max], str);
	
  	return 0;
}

The Output of the above c program; as follows:

Please Enter any String :  hello world
Character 'l' appears Maximum of 3 Times in a Given String :  hello world 

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

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

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

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

The Output of the above c program; as follows:

Please Enter any String :  hello world
Character 'l' appears Maximum of 3 Times in a Given String :  hello world 

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

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