fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void create_arr(int * A, int length, int Xmin, int Xmax)
  6. {
  7. int i;
  8. for (i=0; i<length; i++)
  9. {
  10. A[i] = -1000+rand()%(Xmax-Xmin+1);
  11. }
  12. }
  13.  
  14. void sort_arr(int * A, int length)
  15. {
  16. int pos, i;
  17. for (pos=length-1; pos>0; pos--)
  18. {
  19. for (i=0; i<pos; i++)
  20. {
  21. if (A[i]>A[i+1])
  22. {
  23. int a = A[i];
  24. A[i] = A[i+1];
  25. A[i+1] = a;
  26. }
  27. }
  28. }
  29. }
  30.  
  31. void print_arr(int * A, int length)
  32. {
  33. int i;
  34. for (i=0; i<length; i++)
  35. {
  36. printf("%d ", A[i]);
  37. }
  38. }
  39.  
  40. int main()
  41. {
  42. clock_t start, stop;
  43. int length=30;
  44. int A[length];
  45. int i, Xmin = -1000, Xmax = 1000;
  46. srand(time(NULL));
  47. start = clock();
  48.  
  49. create_arr(A, length, Xmin, Xmax);
  50.  
  51. printf("Массив до:\n");
  52. print_arr(A, length);
  53.  
  54. sort_arr(A, length);
  55.  
  56. printf("\nМассив после:\n");
  57. print_arr(A, length);
  58.  
  59. stop = clock();
  60. printf("\nВремя выполнения: %f сек.", ((double) (stop - start)) / CLK_TCK);
  61. return 0;
  62. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Массив до:
338 902 -874 546 709 132 841 -528 752 -628 913 -896 -503 242 819 834 -335 498 -630 -845 236 8 -841 -639 610 917 708 540 407 -296 
Массив после:
-896 -874 -845 -841 -639 -630 -628 -528 -503 -335 -296 8 132 236 242 338 407 498 540 546 610 708 709 752 819 834 841 902 913 917 
Время выполнения: 0.000000 сек.