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 0.01s 5288KB
stdin
Standard input is empty
stdout
Массив до:
211 543 273 -629 -540 338 -319 -747 -661 -162 819 583 602 717 88 -691 -178 -82 940 136 -349 -520 493 501 954 -179 -258 404 870 -340 
Массив после:
-747 -691 -661 -629 -540 -520 -349 -340 -319 -258 -179 -178 -162 -82 88 136 211 273 338 404 493 501 543 583 602 717 819 870 940 954 
Время выполнения: 0.000000 мсек.