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. start = clock();
  9. int length=30;
  10. int A[length];
  11. int i, pos, Xmin = -1000, Xmax = 1000;
  12. srand(time(NULL));
  13. for (i=0; i<length; i++)
  14. {
  15. A[i] = -1000+rand()%(Xmax-Xmin+1);
  16. }
  17. printf("Массив до:\n");
  18. for (i=0; i<length; i++)
  19. {
  20. printf("%d ", A[i]);
  21. }
  22. for (pos=length-1; pos>0; pos--)
  23. {
  24. for (i=0; i<pos; i++)
  25. {
  26. if (A[i]>A[i+1])
  27. {
  28. int a = A[i];
  29. A[i] = A[i+1];
  30. A[i+1] = a;
  31. }
  32. }
  33. }
  34. stop = clock();
  35. printf("\nМассив после:\n");
  36. for (i=0; i<length; i++)
  37. {
  38. printf("%d ", A[i]);
  39. }
  40. printf("\nВремя выполнения: %f сек.", ((double) (stop - start)) / CLK_TCK);
  41. return 0;
  42. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Массив до:
-551 826 113 653 212 123 -458 934 739 391 -140 623 45 878 -521 855 -387 639 837 435 465 141 -186 574 367 63 -374 -701 -633 504 
Массив после:
-701 -633 -551 -521 -458 -387 -374 -186 -140 45 63 113 123 141 212 367 391 435 465 504 574 623 639 653 739 826 837 855 878 934 
Время выполнения: 0.000000 сек.