fork download
  1. #include<stdio.h>
  2. #include<time.h>
  3. #include<stdlib.h>
  4. clock_t start,end;
  5. double cpu_time_used;
  6. int a[1000000];
  7.  
  8. void swap(int*a,int*b)
  9. {
  10. int temp=*a;
  11. *a=*b;
  12. *b=temp;
  13. }
  14. void SelectSort(int a[],int n)
  15. {
  16. int i,j,min;
  17. for(i=0;i<n;i++)
  18. {
  19. min=i;
  20. for(i=0;i<n;i++)
  21. {
  22. if(a[j]<a[min])
  23. min=j;
  24. }
  25. swap(&a[min],&a[i]);
  26. }
  27. }
  28. void PrintArray(int a[],int n)
  29. {
  30. int i;
  31. for(i=0;i<n;i++)
  32. printf("\n %d \t",a[i]);
  33. printf("\n");
  34. }
  35. int main()
  36. {
  37. int i=0,n=0;
  38. printf("\n enter no of elements in array\n");
  39. scanf("\n %d ",&n);
  40. for(i=0;i<n;i++)
  41. {
  42. a[i]=rand()%(100000-10000+1)+1000;
  43. }
  44. for(i=0;i<n;i++)
  45. {
  46. printf("\n %d \t",a[i]);
  47. }
  48. int size=sizeof (a)/sizeof(a[0]);
  49. start=clock();
  50. SelectSort(a,n);
  51. end=clock();
  52. printf("\nsorted array in ascending order\n");
  53. PrintArray(a,n);
  54. cpu_time_used=((double) (end-start))/CLOCKS_PER_SEC;
  55. printf("\n cpu_time_used= %f \n", cpu_time_used*1000);
  56. return 0;
  57. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
 enter no of elements in array

sorted array in ascending order


 cpu_time_used= 0.000000