fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. void swap(int *a,int*b){
  5. int temp=*a;
  6. *a=*b;
  7. *b=temp;
  8. }
  9. void sel(int a[],int n){
  10. int min;
  11. for(int i=0;i<n-1;i++){
  12. min=i;
  13. for(int j=i+1;j<n;j++){
  14. if(a[j]<a[min])
  15. min=j;
  16. }
  17. swap(&a[i],&a[min]);
  18. }
  19. }
  20. int main(){
  21. time_t start,end;
  22. double cpu;
  23. int n,a[10000];
  24. printf("\nenter the number of elements ");
  25. scanf("%d",&n);
  26. srand(100);
  27. for(int i=0;i<n;i++){
  28.  
  29. a[i]=rand()%1000;
  30. printf("%d ",a[i]);
  31.  
  32. }
  33. start=clock();
  34. sel(a,n);
  35. end=clock();
  36. for(int i=0;i<n;i++)
  37. printf("\n%d",a[i]);
  38.  
  39. cpu=(double)(end-start)/CLOCKS_PER_SEC;
  40. printf("\n the cpu time taken is %f",cpu*1000);
  41. return 0;
  42.  
  43. }
Success #stdin #stdout 0s 5324KB
stdin
1
2
10
42
11
stdout
enter the number of elements 240 
240
 the cpu time taken is 0.000000