Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_SEQ 100
- void analyzeFrequencies(int mainArray[], int counter[], int* mOI, int* numOfOccurences);
- int main()
- {
- int i=0, *mOI=0, *numOfOccurences=0, tempNum=0, mainArray[MAX_SEQ] = {0}, counter[MAX_SEQ] = {0};
- printf("Please enter a integer between 0-1000.nSequence will stop when you enter negative integer of after MAX_SEQ integers.nn");
- do
- {
- if( scanf("%d", &tempNum) == 1)
- {
- if (tempNum <= 1000)
- {
- if (tempNum < 0)
- {
- printf("You decided to exit the sequence. Your array entered is:n");
- }
- else
- {
- mainArray[i] = tempNum;
- counter[tempNum]++;
- ++i;
- }
- }
- else
- printf("Please enter a number between 0-1000. Exit sequence by entering negative number.n");
- }
- else
- printf("nError.n");
- } while(tempNum > 0 && i < MAX_SEQ);
- analyzeFrequencies(mainArray, counter, mOI, numOfOccurences); //This is where the problem occurs.
- if (i == 0)
- {
- printf("You entered no sequence.");
- }
- else
- {
- printf("nSequence:n");
- for(int j=0; j<i; j++)
- {
- printf("[%d] %dn", j, mainArray[j]);
- }
- printf("Most occurred item: %dnOccurred %d times!", *mOI, *numOfOccurences);
- }
- }
- void analyzeFrequencies(int mainArray[], int counter[], int* mOI, int* numOfOccurences)
- {
- for(int i=0; i<MAX_SEQ; i++)
- {
- if(counter[i] > *numOfOccurences)
- {
- *mOI = i;
- *numOfOccurences = counter[i];
- }
- }
- }
Add Comment
Please, Sign In to add comment