-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmaxchar.c
More file actions
38 lines (33 loc) · 909 Bytes
/
Copy pathmaxchar.c
File metadata and controls
38 lines (33 loc) · 909 Bytes
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
#include<stdio.h>
#define ASCII_SIZE 256
char getMaxOccuringChar(char* str)
{
// Create array to keep the count of individual
// characters and initialize the array as 0
int count[ASCII_SIZE]={0} ;
// Construct character count array from the input
// string.
int len = strlen(str);
for (int i=0; i<len; i++)
count[str[i]]++;
int max = -1; // Initialize max count
char result; // Initialize result
// Traversing through the string and maintaining
// the count of each character
for (int i = 0; i < len; i++) {
if (max < count[str[i]]) {
max = count[str[i]];
result = str[i];
}
}
return result;
}
// Driver program to test the above function
int main()
{
char str[] = "akash";
printf("Max occurring character is\n ");
char p= getMaxOccuringChar(str);
printf("%c",p);
return 0;
}