Advertisement
Hanaigi

Untitled

Oct 26th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. 1)
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. const int N = 58;
  6. int main()
  7. {
  8. float a = 2.14, b = -4.21, c = 3.25, xn = -4.5, xk = -33.5, h = 0.5;
  9. int A[N];
  10. for (int i = 0; i <= 57; i++)
  11. {
  12. A[i] = a * pow(xn, 2) * sin(xn) + b * xn + c;
  13. xn -= h;
  14. }
  15. for (int i = 0; i < N - 1; i++) {
  16. for (int j = 0; j < N - 1 - i; j++) {
  17. if (A[j] < A[j + 1]) {
  18. int temp = A[j];
  19. A[j] = A[j + 1];
  20. A[j + 1] = temp;
  21. }
  22. }
  23. }
  24. for (int i = 0; i < N; i++) {
  25. printf("%d ", A[i]);
  26. }
  27. }
  28. ----------------------------------------------------------------------
  29. 2)
  30. #include <stdio.h>
  31. #include <math.h>
  32. #include <stdlib.h>
  33. const int N = 15;
  34. int main()
  35. {
  36. int A[N], flag = 1;
  37. for (int i = 0; i < N; i++)
  38. A[i] = (int)rand() * (10 - 0) / RAND_MAX + 0;
  39. for (int i = 0; i < N; i++)
  40. {
  41. for (int j = i + 1; j < N; j++)
  42. {
  43. if (A[i] == A[j])
  44. flag = 0;
  45. }
  46. if (flag)
  47. printf("%d ", A[i]);
  48. flag = 1;
  49. }
  50. }
  51. -----------------------------------------------------------------------------
  52. 3)
  53. #include <stdio.h>
  54. #include <math.h>
  55. #include <stdlib.h>
  56. const int N = 20;
  57. int main()
  58. {
  59. float A[N], B[N];
  60. int j = 0;
  61. for (int i = 0; i < N; i++)
  62. A[i] = (float)rand() / (float)(RAND_MAX / 20) - 10;
  63. for (int i = 0; i < N; i++)
  64. {
  65. if (A[i] >= 0) { B[j] = A[i]; j++; }
  66. printf("%f ", A[i]);
  67. }
  68. printf("\n");
  69. for (int i = 0; i < j; i++)
  70. printf("%f ", B[i]);
  71. }
  72. ---------------------------------------------------------------------------
  73. 4)
  74. #include <stdio.h>
  75. #include <math.h>
  76. #include <stdlib.h>
  77. const int N = 20;
  78. const int N1 = 40;
  79. int main()
  80. {
  81. int C[N], D[N], E[N1];
  82. for (int i = 0; i < N; i++)
  83. {
  84. C[i] = (int)rand() * (20 - 0) / RAND_MAX + 0;
  85. D[i] = (int)rand() * (20 - 0) / RAND_MAX + 0;
  86. }
  87. for (int i = 0; i < N - 1; i++) {
  88. for (int j = 0; j < N - 1; j++) {
  89. if (C[j] > C[j + 1]) {
  90. int temp = C[j];
  91. C[j] = C[j + 1];
  92. C[j + 1] = temp;
  93. }
  94. }
  95. }
  96. for (int i = 0; i < N - 1; i++) {
  97. for (int j = 0; j < N - 1; j++) {
  98. if (D[j] > D[j + 1]) {
  99. int temp = D[j];
  100. D[j] = D[j + 1];
  101. D[j + 1] = temp;
  102. }
  103. }
  104. }
  105. for (int i = 0, j = 0, k = 0; k < N1; k++)
  106. {
  107. if (i < N && C[i] < D[j])
  108. {
  109. E[k] = C[i];
  110. i++;
  111. }
  112. else
  113. {
  114. E[k] = D[j];
  115. j++;
  116. }
  117. }
  118. for (int k = 0; k < N1; k++)
  119. printf("%d\n", E[k]);
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement