BatBlaster

Compsci230Hw1

Feb 25th, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //David Levin
  2. //10877264
  3. //Finds number of occurences of each number in an array
  4. //At least it is supposed to.  I need to actually do my hw before the last minute.
  5. //Compiled on Dev-C++
  6. #include <stdio.h>
  7. #include <ctype.h>
  8.  
  9. int main (void)
  10. {
  11.     int intList[15], uniqList[15], freqList[15];
  12.     int c, i, flag, t;
  13.     flag = 0;
  14.     t = 0;
  15.     printf("Input array");
  16.     for (c = 0;c < 15;c++)
  17.           {
  18.           intList[c] = 0;  
  19.           uniqList[c] = 0;
  20.           freqList[c] = 0;
  21.           }
  22.     for (c = 0;c < 15;c++)
  23.           {
  24.           scanf(" %i", &intList[c]);  
  25.           }
  26.     uniqList[0] = intList[0];
  27.     printf("    ");
  28.     for (c = 1;c < 15;c++)
  29.           {
  30.                  flag = 0;
  31.                  for (i = 0; i < 15; i++)
  32.                  {
  33.                            if (intList[c] == uniqList[i]);
  34.                            {
  35.                                 flag = 1;
  36.                                 freqList[i]++;
  37.                                 break;
  38.                            }
  39.                  }
  40.           }
  41.                            if (flag == 0)
  42.                  {
  43.                              uniqList[t] = intList[c];
  44.                              t++;
  45.                  }
  46.     for (c = 0;c < 15;c++)
  47.           {
  48.                 for (t=0; t < 15; t++)
  49.                 {
  50.                  if(uniqList[c] == intList[t])
  51.                                {
  52.                                      freqList[c]++;
  53.                                }
  54.                  }
  55.     for (c = 0;c < 15;c++)
  56.           {
  57.                  if(freqList[c] != 0)
  58.                                {
  59.                                      freqList[c]=freqList[c]-14;
  60.                                }
  61.                  }
  62. //stupid workaround, but I am in a hurry.
  63.                  printf("\nN           Count \n");
  64.     for (c = 0;c < 15;c++)
  65.           {
  66.           printf(" %i           ;%i  \n", uniqList[c], freqList[c]);    
  67.           }
  68.     printf("STOP HITTING ENTER!");
  69.     scanf("%i",i);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment