Guest User

Untitled

a guest
Dec 12th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MAX_SEQ 100
  5.  
  6. void analyzeFrequencies(int mainArray[], int counter[], int* mOI, int* numOfOccurences);
  7.  
  8. int main()
  9. {
  10. int i=0, *mOI=0, *numOfOccurences=0, tempNum=0, mainArray[MAX_SEQ] = {0}, counter[MAX_SEQ] = {0};
  11.  
  12. printf("Please enter a integer between 0-1000.nSequence will stop when you enter negative integer of after MAX_SEQ integers.nn");
  13.  
  14. do
  15. {
  16. if( scanf("%d", &tempNum) == 1)
  17. {
  18. if (tempNum <= 1000)
  19. {
  20. if (tempNum < 0)
  21. {
  22. printf("You decided to exit the sequence. Your array entered is:n");
  23. }
  24. else
  25. {
  26. mainArray[i] = tempNum;
  27. counter[tempNum]++;
  28. ++i;
  29. }
  30. }
  31. else
  32. printf("Please enter a number between 0-1000. Exit sequence by entering negative number.n");
  33. }
  34. else
  35. printf("nError.n");
  36.  
  37. } while(tempNum > 0 && i < MAX_SEQ);
  38.  
  39. analyzeFrequencies(mainArray, counter, mOI, numOfOccurences); //This is where the problem occurs.
  40.  
  41. if (i == 0)
  42. {
  43. printf("You entered no sequence.");
  44. }
  45. else
  46. {
  47. printf("nSequence:n");
  48. for(int j=0; j<i; j++)
  49. {
  50. printf("[%d] %dn", j, mainArray[j]);
  51. }
  52.  
  53. printf("Most occurred item: %dnOccurred %d times!", *mOI, *numOfOccurences);
  54. }
  55. }
  56.  
  57. void analyzeFrequencies(int mainArray[], int counter[], int* mOI, int* numOfOccurences)
  58. {
  59. for(int i=0; i<MAX_SEQ; i++)
  60. {
  61. if(counter[i] > *numOfOccurences)
  62. {
  63. *mOI = i;
  64. *numOfOccurences = counter[i];
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment