Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #ifndef _H_FUNCTIONS_H_
  2. #define _H_FUNCTIONS_H_
  3.  
  4. int returnMostOccuringSym(char *, unsigned);
  5.  
  6. #endif
  7.  
  8.  
  9. #include "functions.h"
  10. #include <iostream>
  11. #include <time.h>
  12.  
  13. int returnMostOccuringSym(char * string, unsigned size)
  14. {
  15.     char ch = string[0];
  16.     int occures = 0;
  17.     int max = 0;
  18.     for (size_t i = 1; i < size; i++)
  19.     {
  20.         for (size_t k = 0; k < size; k++)
  21.         {
  22.             if (ch == string[k])
  23.             {
  24.                 occures++;
  25.             }
  26.         }
  27.         if (occures > max)
  28.         {
  29.             max = occures;
  30.  
  31.         }
  32.     }
  33.     return 0;
  34. }
  35.  
  36.  
  37. #include "functions.h"
  38. #include <iostream>
  39.  
  40. using namespace std;
  41.  
  42. int main() {
  43.     int size;
  44.     cout << "Enter the size of string" << endl;
  45.     cin >> size;
  46.  
  47.     char * string = new char[size];
  48.     for (int i = 0; i < size; i++)
  49.     {
  50.         int randomVal = rand() % 256 + 1;
  51.         string[i] = randomVal;
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement