Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. //most often repeated char
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <stdarg.h>
  6. #include <string.h>
  7. #define SIZE 27
  8.  
  9. void output_m_repeated(int num, char a, ...);
  10.  
  11. int main(void)
  12. {
  13.     char a = 'j';
  14.     int num = 4;
  15.     printf(" '%c', 'k', 'j', 'a'\n", a);
  16.     output_m_repeated(num, a, 'k', 'j', 'a');
  17.  
  18.     _getch();
  19.     return 0;
  20. }
  21. void output_m_repeated(int num, char a, ...)
  22. {
  23.     va_list vl;
  24.     va_start(vl, num);
  25.     int index = 0;
  26.     char alphabet[SIZE] = "abcdefghijklmnopqrstuvwxyz";
  27.     int count_alpha[SIZE] = { 0 };
  28.     char curr_char = 0;
  29.     for (int i = 0; i < num; i++)
  30.     {
  31.         curr_char = va_arg(vl, int);
  32.         for (int j = 0; j < SIZE; j++)
  33.         {
  34.             if (curr_char == alphabet[j])
  35.             {
  36.                 ++count_alpha[j];
  37.                 break;
  38.             }
  39.             else continue;
  40.         }
  41.     }
  42.     int max = count_alpha[0];
  43.     for (int i = 1; i < SIZE; ++i)
  44.     {
  45.         if (max < count_alpha[i])
  46.         {
  47.             max = count_alpha[i];
  48.             index = i;
  49.         }
  50.     }
  51.     printf("Most often repeated character: %c", alphabet[index]);
  52.     va_end(vl);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement