• Source
    1. #include<stdio.h>
    2. #include<time.h>
    3. void Exch(int *p, int *q){
    4. int temp = *p;
    5. *p = *q;
    6. *q = temp;
    7. }
    8. void QuickSort(int a[], int low, int high){
    9. int i, j, key, k;
    10. if(low>=high)
    11. return;
    12. key=low;
    13. i=low+1;
    14. j=high;
    15. while(i<=j){
    16. while ( a[i] <= a[key] )
    17. i=i+1;
    18. while ( a[j] > a[key] )
    19. j=j -1;
    20. if(i<j)
    21. Exch(&a[i], &a[j]);
    22. }
    23. Exch(&a[j], &a[key]);
    24. QuickSort(a, low, j-1);
    25. QuickSort(a, j+1, high);
    26. }
    27. void main(){
    28. int n, a[1000],k;
    29. clock_tst,et; double ts; clrscr();
    30. printf("\n Enter How many Numbers: ");
    31. scanf("%d", &n);
    32. printf("\nThe Random Numbers are:\n");
    33. for(k=1; k<=n; k++){
    34. a[k]=rand();
    35. printf("%d\t",a[k]);
    36. }
    37. st=clock();
    38. QuickSort(a, 1, n);
    39. et=clock();
    40. ts=(double)(et-st)/CLOCKS _PER_SEC;
    41. printf("\nSorted Numbers are: \n ");
    42. for(k=1; k<=n; k++)
    43. printf("%d\t", a[k]);
    44. printf("\nThe time taken is %e",ts);
    45. }
    46.