Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //most often repeated char
- #include <stdio.h>
- #include <conio.h>
- #include <stdarg.h>
- #include <string.h>
- #define SIZE 27
- void output_m_repeated(int num, char a, ...);
- int main(void)
- {
- char a = 'j';
- int num = 4;
- printf(" '%c', 'k', 'j', 'a'\n", a);
- output_m_repeated(num, a, 'k', 'j', 'a');
- _getch();
- return 0;
- }
- void output_m_repeated(int num, char a, ...)
- {
- va_list vl;
- va_start(vl, num);
- int index = 0;
- char alphabet[SIZE] = "abcdefghijklmnopqrstuvwxyz";
- int count_alpha[SIZE] = { 0 };
- char curr_char = 0;
- for (int i = 0; i < num; i++)
- {
- curr_char = va_arg(vl, int);
- for (int j = 0; j < SIZE; j++)
- {
- if (curr_char == alphabet[j])
- {
- ++count_alpha[j];
- break;
- }
- else continue;
- }
- }
- int max = count_alpha[0];
- for (int i = 1; i < SIZE; ++i)
- {
- if (max < count_alpha[i])
- {
- max = count_alpha[i];
- index = i;
- }
- }
- printf("Most often repeated character: %c", alphabet[index]);
- va_end(vl);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement