66 lines
1.8 KiB
C
66 lines
1.8 KiB
C
/*
|
|
* C Program To Find the Highest Frequency Character in a String
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
char string1[100], visited[100];
|
|
int count[100] = {0}, flag = 0;
|
|
|
|
void main()
|
|
{
|
|
int i, j = 0, k = 0, l, max, index;
|
|
printf("Enter a string : ");
|
|
scanf("%[^
|
|
]s", string1);
|
|
l = strlen(string1);
|
|
for (i = 0; i < l; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
visited[j++] = string1[i];
|
|
count[j - 1]++;
|
|
}
|
|
else
|
|
{
|
|
for (k = 0; k < j; k++)
|
|
{
|
|
if (string1[i] == visited[k])
|
|
{
|
|
count[k]++;
|
|
flag = 1;
|
|
}
|
|
}
|
|
if (flag == 0)
|
|
{
|
|
visited[j++] = string1[i];
|
|
count[j - 1]++;
|
|
}
|
|
flag = 0;
|
|
}
|
|
}
|
|
for (i = 0; i < j; i++)
|
|
{
|
|
if ((i == 0) && (visited[i] != ' '))
|
|
{
|
|
max = count[i];
|
|
continue;
|
|
}
|
|
if ((max < count[i]) && (visited[i] != ' '))
|
|
{
|
|
max = count[i];
|
|
index = i;
|
|
}
|
|
}
|
|
printf("
|
|
Max repeated character in the string = %c ", visited[index]);
|
|
printf("
|
|
It occurs %d times", count[index]);
|
|
}
|
|
|
|
|
|
Enter a string :
|
|
Welcome to your C Programming Class !
|
|
|
|
Max repeated character in the string = o
|
|
It occurs 4 times |