Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //David Levin
- //10877264
- //Finds number of occurences of each number in an array
- //At least it is supposed to. I need to actually do my hw before the last minute.
- //Compiled on Dev-C++
- #include <stdio.h>
- #include <ctype.h>
- int main (void)
- {
- int intList[15], uniqList[15], freqList[15];
- int c, i, flag, t;
- flag = 0;
- t = 0;
- printf("Input array");
- for (c = 0;c < 15;c++)
- {
- intList[c] = 0;
- uniqList[c] = 0;
- freqList[c] = 0;
- }
- for (c = 0;c < 15;c++)
- {
- scanf(" %i", &intList[c]);
- }
- uniqList[0] = intList[0];
- printf(" ");
- for (c = 1;c < 15;c++)
- {
- flag = 0;
- for (i = 0; i < 15; i++)
- {
- if (intList[c] == uniqList[i]);
- {
- flag = 1;
- freqList[i]++;
- break;
- }
- }
- }
- if (flag == 0)
- {
- uniqList[t] = intList[c];
- t++;
- }
- for (c = 0;c < 15;c++)
- {
- for (t=0; t < 15; t++)
- {
- if(uniqList[c] == intList[t])
- {
- freqList[c]++;
- }
- }
- for (c = 0;c < 15;c++)
- {
- if(freqList[c] != 0)
- {
- freqList[c]=freqList[c]-14;
- }
- }
- //stupid workaround, but I am in a hurry.
- printf("\nN Count \n");
- for (c = 0;c < 15;c++)
- {
- printf(" %i ;%i \n", uniqList[c], freqList[c]);
- }
- printf("STOP HITTING ENTER!");
- scanf("%i",i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment