0

FIND THE DIFFERENCE

NEED SOME HELP: Code works fine when doing PROBLEM 1, but i need help when i need to display two outputs just like in PROBLEM 2. And use either of the two depending on the input but I dont know how to apply it in a single program PROBLEM 1: INPUT: ABABABABABc OUTPUT: 'c' = 1 PROBLEM 2: INPUT: ABABABABABac OUTPUT: 'a' 'c' = 1 https://code.sololearn.com/WXyd6modz3G8/?ref=app

26th Mar 2020, 6:24 AM
Kool
Kool - avatar
5 Answers
0
I just added some lines at the end. #include <stdio.h> #define MAX_SIZE 100 #define MAX_CHARS 255 int main() { char str[MAX_SIZE]; int freq[MAX_CHARS]; int i = 0, min; int ascii; printf("Enter any character: "); gets(str); for(i=0; i<MAX_CHARS; i++) { freq[i] = 0; } i=0; while(str[i] != '\0') { ascii = (int)str[i]; freq[ascii] += 1; i++; } min = 0; for(i=0; i<MAX_CHARS; i++) { if(freq[i] != 0) { if(freq[min] == 0 || freq[i] < freq[min]) min = i; } } printf("Minimum occurring character is "); for(i=0;i<MAX_CHARS;i++){ if(freq[i]==freq[min]){ printf("'%c'",i); } } printf("=%d",freq[min]); return 0; }
26th Mar 2020, 7:47 AM
John Robotane
John Robotane - avatar
0
John Robotane Thank You and Godbless
26th Mar 2020, 7:48 AM
Kool
Kool - avatar
0
thanks Alby !
26th Mar 2020, 7:50 AM
John Robotane
John Robotane - avatar
0
John Robotane My question was updated can i still use your code in that case?
26th Mar 2020, 7:54 AM
Kool
Kool - avatar
0
what have you added to the question?
26th Mar 2020, 7:57 AM
John Robotane
John Robotane - avatar