Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1)
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- const int N = 58;
- int main()
- {
- float a = 2.14, b = -4.21, c = 3.25, xn = -4.5, xk = -33.5, h = 0.5;
- int A[N];
- for (int i = 0; i <= 57; i++)
- {
- A[i] = a * pow(xn, 2) * sin(xn) + b * xn + c;
- xn -= h;
- }
- for (int i = 0; i < N - 1; i++) {
- for (int j = 0; j < N - 1 - i; j++) {
- if (A[j] < A[j + 1]) {
- int temp = A[j];
- A[j] = A[j + 1];
- A[j + 1] = temp;
- }
- }
- }
- for (int i = 0; i < N; i++) {
- printf("%d ", A[i]);
- }
- }
- ----------------------------------------------------------------------
- 2)
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- const int N = 15;
- int main()
- {
- int A[N], flag = 1;
- for (int i = 0; i < N; i++)
- A[i] = (int)rand() * (10 - 0) / RAND_MAX + 0;
- for (int i = 0; i < N; i++)
- {
- for (int j = i + 1; j < N; j++)
- {
- if (A[i] == A[j])
- flag = 0;
- }
- if (flag)
- printf("%d ", A[i]);
- flag = 1;
- }
- }
- -----------------------------------------------------------------------------
- 3)
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- const int N = 20;
- int main()
- {
- float A[N], B[N];
- int j = 0;
- for (int i = 0; i < N; i++)
- A[i] = (float)rand() / (float)(RAND_MAX / 20) - 10;
- for (int i = 0; i < N; i++)
- {
- if (A[i] >= 0) { B[j] = A[i]; j++; }
- printf("%f ", A[i]);
- }
- printf("\n");
- for (int i = 0; i < j; i++)
- printf("%f ", B[i]);
- }
- ---------------------------------------------------------------------------
- 4)
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- const int N = 20;
- const int N1 = 40;
- int main()
- {
- int C[N], D[N], E[N1];
- for (int i = 0; i < N; i++)
- {
- C[i] = (int)rand() * (20 - 0) / RAND_MAX + 0;
- D[i] = (int)rand() * (20 - 0) / RAND_MAX + 0;
- }
- for (int i = 0; i < N - 1; i++) {
- for (int j = 0; j < N - 1; j++) {
- if (C[j] > C[j + 1]) {
- int temp = C[j];
- C[j] = C[j + 1];
- C[j + 1] = temp;
- }
- }
- }
- for (int i = 0; i < N - 1; i++) {
- for (int j = 0; j < N - 1; j++) {
- if (D[j] > D[j + 1]) {
- int temp = D[j];
- D[j] = D[j + 1];
- D[j + 1] = temp;
- }
- }
- }
- for (int i = 0, j = 0, k = 0; k < N1; k++)
- {
- if (i < N && C[i] < D[j])
- {
- E[k] = C[i];
- i++;
- }
- else
- {
- E[k] = D[j];
- j++;
- }
- }
- for (int k = 0; k < N1; k++)
- printf("%d\n", E[k]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement