Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define SIZEA 100
- #define SIZEFREQ 10
- int main()
- {
- int a[SIZEA]={0},frequency[SIZEFREQ]={0};
- int i,temp,gothrough;
- srand(time(NULL));
- for(i=0;i<=SIZEA-1;i++)
- {
- a[i]=rand() %10 +1;
- ++frequency[a[i]-1];
- }
- printf("These are the elements in the vector:\n");
- for(i=0;i<=SIZEA-1;i++)
- {
- printf("%3d,",a[i]);
- }
- printf("\nLet's try to put them in order\n");
- for(gothrough=0;gothrough<=SIZEA-1;gothrough++)
- {
- for(i=0;i<=SIZEA-2;i++)
- {
- if (a[i]>a[i+1])
- {
- temp=a[i];
- a[i]=a[i+1];
- a[i+1]=temp;
- }
- }
- }
- for(i=0;i<=SIZEA-1;i++)
- {
- printf("%3d,",a[i]);
- }
- printf("\n\nValue Frequency\n");
- for(i=0;i<=SIZEFREQ-1;i++)
- {
- printf("%5d%10d\n",i+1,frequency[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement