-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring11.c
More file actions
60 lines (59 loc) · 1.22 KB
/
string11.c
File metadata and controls
60 lines (59 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Write a program to print the highest frequency characters in a string.
#include<stdio.h>
#include<string.h>
void checkCharfrequency(char str[]);
int main()
{
char str[10];
printf("Enter your string : ");
fgets(str,10,stdin);
checkCharfrequency(str);
return 0;
}
void checkCharfrequency(char str[])
{
int count[10],i=0,maxcount=0;
char ch[10];
while(count[i<10])
{
count[i]=0;
i++;
}
for(int i=0;str[i]!='\0';i++)
{
for(int j=0;str[j]!='\0';j++)
{
if(str[i]==str[j])
{
count[i]++;
ch[i]=str[i];
}
else
{
count[i]=1;
ch[i]=str[i];
}
}
}
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(count[i]>count[j])
{
maxcount=count[i];
}
else
{
maxcount=count[j];
}
}
}
for(int i=0;i<10;i++)
{
if(count[i]==maxcount)
{
printf("%c has highest frequency in input string which is %d times \n",ch[i],count[i]);
}
}
}