(C program) I want to print most frequently used alphabet
If it is greater than 1, I want to print "?".
The length of the string is less than 1001
ex. input : coffee output : wrong
input : wallet output : l
I don't know what is the problem in this code below.
int main() {
char str[1000];
int alpha[26] = { 0, };
int count = 0;
char c = '?';
scanf("%s", str);
for (int i = 0;str!='\0'; i++) {
if (str >= 'a') {
str -=
32;
alpha[str -
65]++;
}
}
for (int j = 0; j < 26; j++) {
if (count < alpha[j]) {
count =
alpha[j];
c = j;
}
else if (count == alpha[j]) {
c = '?';
}
}
if (c != '?') {
printf("%c", c+65);
}
else {
printf("?");
}
}
(C program) I want to print most frequently used alphabet If it is greater than 1, I want to print "?". The length of th
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
(C program) I want to print most frequently used alphabet If it is greater than 1, I want to print "?". The length of th
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!