Advertisement
Guest User

Untitled

a guest
Nov 27th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define SIZEA 100
  5. #define SIZEFREQ 10
  6.  
  7. int main()
  8. {
  9.     int a[SIZEA]={0},frequency[SIZEFREQ]={0};
  10.     int i,temp,gothrough;
  11.  
  12.     srand(time(NULL));
  13.  
  14.     for(i=0;i<=SIZEA-1;i++)
  15.     {
  16.         a[i]=rand() %10 +1;
  17.         ++frequency[a[i]-1];
  18.     }
  19.  
  20.     printf("These are the elements in the vector:\n");
  21.     for(i=0;i<=SIZEA-1;i++)
  22.     {
  23.         printf("%3d,",a[i]);
  24.     }
  25.  
  26.     printf("\nLet's try to put them in order\n");
  27.     for(gothrough=0;gothrough<=SIZEA-1;gothrough++)
  28.     {
  29.         for(i=0;i<=SIZEA-2;i++)
  30.         {
  31.             if (a[i]>a[i+1])
  32.             {
  33.                 temp=a[i];
  34.                 a[i]=a[i+1];
  35.                 a[i+1]=temp;
  36.             }
  37.         }
  38.     }
  39.  
  40.     for(i=0;i<=SIZEA-1;i++)
  41.     {
  42.         printf("%3d,",a[i]);
  43.     }
  44.  
  45.     printf("\n\nValue Frequency\n");
  46.     for(i=0;i<=SIZEFREQ-1;i++)
  47.     {
  48.         printf("%5d%10d\n",i+1,frequency[i]);
  49.     }
  50.  
  51. return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement