fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void sort_arr(int * A, int length)
  6. {
  7. int pos, i;
  8. for (pos=length-1; pos>0; pos--)
  9. {
  10. for (i=0; i<pos; i++)
  11. {
  12. if (A[i]>A[i+1])
  13. {
  14. int a = A[i];
  15. A[i] = A[i+1];
  16. A[i+1] = a;
  17. }
  18. }
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. clock_t start, stop;
  25. start = clock();
  26. printf("Массив до:\n");
  27. int length=30;
  28. int A[length];
  29. int i, j, pos, Xmin = -1000, Xmax = 1000;
  30. srand(time(NULL));
  31. for (i=0; i<length; i++)
  32. {
  33. A[i] = -1000+rand()%(Xmax-Xmin+1);
  34. printf("%d ", A[i]);
  35. }
  36.  
  37. sort_arr(A, length);
  38.  
  39. printf("\nМассив после:\n");
  40. for (i=0; i<length; i++)
  41. {
  42. printf("%d ", A[i]);
  43. }
  44. stop = clock();
  45. printf("\nВремя выполнения: %f сек.", ((double) (stop - start)) / CLK_TCK);
  46. return 0;
  47. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Массив до:
286 -318 968 -389 -173 521 877 295 -667 415 -957 -468 -56 -136 998 -377 26 -855 711 395 760 456 -641 362 27 341 -419 969 -240 278 
Массив после:
-957 -855 -667 -641 -468 -419 -389 -377 -318 -240 -173 -136 -56 26 27 278 286 295 341 362 395 415 456 521 711 760 877 968 969 998 
Время выполнения: 0.000000 сек.