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 5320KB
stdin
Standard input is empty
stdout
Массив до:
965 -470 491 -533 225 601 -811 -672 -474 -311 -743 -453 451 592 498 287 486 -860 -867 -148 -422 -288 -650 -228 -609 -359 -832 -285 753 988 
Массив после:
-867 -860 -832 -811 -743 -672 -650 -609 -533 -474 -470 -453 -422 -359 -311 -288 -285 -228 -148 225 287 451 486 491 498 592 601 753 965 988 
Время выполнения: 0.000000 мсек.