- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- #include <stdlib.h>
- #include <unistd.h>
- typedef unsigned int Uint;
- #define ARRAY_MAX 100
- static int sort_int_function(const void *a , const void *b)
- {
- return *(int *)a - *(int *)b;
- }
- int getNumber()
- {
- int num;
- num = rand() % ARRAY_MAX + 1;
- return num;
- }
- /*
- *in order to get different datas in this array
- */
- void array_get(int *array)
- {
- int i = 0;
- int j = 0;
- int temp;
- int flag = 1;
- for(i = 0 ; i < ARRAY_MAX ; )
- {
- temp = getNumber();
- for(j = 0 ; j <= i ; j++)
- {
- if(temp == array[j] )
- {
- flag = 0;
- break;
- }
- flag = 1;
- }
- if(flag)
- {
- array[i] = temp;
- i++;
- }
- }
- return ;
- }
- /*
- *@barif main function
- */
- int main(int argc , char **argv)
- {
- int i = 0;
- int count = 0;
- int array[ARRAY_MAX];
- srand((Uint)time(0));
- array_get(array);
- printf("\n*******************************\n");
- for(i = 0 ; i < ARRAY_MAX ; i++)
- {
- printf("%6d" , array[i]);
- if((count + 1) % 5 == 0)
- {
- printf("\n");
- }
- count ++;
- }
- printf("\n***************after sort****************\n");
- qsort((void *)array , ARRAY_MAX , sizeof(int) , sort_int_function );
- count = 0;
- for(i = 0 ; i < ARRAY_MAX ; i++)
- {
- printf("%6d" , array[i]);
- if((count + 1) % 5 == 0)
- {
- printf("\n");
- sleep(1);
- }
- count ++;
- }
- printf("\n");
- return 0;
- }