fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main()
  6. {
  7. clock_t start, stop;
  8. int length=30;
  9. int A[length];
  10. int i, pos, Xmin = -1000, Xmax = 1000;
  11. srand(time(NULL));
  12.  
  13. start = clock();
  14.  
  15. for (i=0; i<length; i++)
  16. {
  17. A[i] = -1000+rand()%(Xmax-Xmin+1);
  18. }
  19.  
  20. printf("Массив до:\n");
  21. for (i=0; i<length; i++)
  22. {
  23. printf("%d ", A[i]);
  24. }
  25.  
  26. for (pos=length-1; pos>0; pos--)
  27. {
  28. for (i=0; i<pos; i++)
  29. {
  30. if (A[i]>A[i+1])
  31. {
  32. int a = A[i];
  33. A[i] = A[i+1];
  34. A[i+1] = a;
  35. }
  36. }
  37. }
  38. stop = clock();
  39.  
  40. printf("\nМассив после:\n");
  41. for (i=0; i<length; i++)
  42. {
  43. printf("%d ", A[i]);
  44. }
  45.  
  46. printf("\nВремя выполнения: %f мсек.", ((double) (stop - start)) / CLK_TCK);
  47. return 0;
  48. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Массив до:
635 501 699 925 -303 438 -859 -260 -756 -608 -679 310 683 -873 -968 485 547 535 -580 -402 256 -826 -711 -606 -212 -263 786 775 182 -71 
Массив после:
-968 -873 -859 -826 -756 -711 -679 -608 -606 -580 -402 -303 -263 -260 -212 -71 182 256 310 438 485 501 535 547 635 683 699 775 786 925 
Время выполнения: 0.000000 мсек.