Advertisement
Sitisom

1.6

Oct 16th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5.  
  6. double numGenerator(int i, float x) {
  7.     float r;
  8.     //r = (pow(-1, i)*log(1 + x * x)) / sqrt(1 + x * x);
  9.     r = (pow(-1, i)*sin(1 + x + x * x)) / (1 + x * x);
  10.     return r;
  11. }
  12.  
  13. void bubbleSort(float y[], int N) {
  14.     double t = 0;
  15.     for (int i = 0; i < N; i++) {
  16.         for (int j = N - 1; j >= (i + 1); j--) {
  17.             if (y[j] >= y[j - 1]) {
  18.                 t = y[j];
  19.                 y[j] = y[j - 1];
  20.                 y[j - 1] = t;
  21.             }
  22.         }
  23.     }
  24. }
  25.  
  26. int main()
  27. {
  28.     int N,k;
  29.     cout << "Enter n: "; cin >>N;
  30.     float *y = new float[N];
  31.     cout << "Enter x: "; cin >> k;
  32.     y[0] = numGenerator(0, k);
  33.     for (int i = 1; i < N; i++)
  34.         y[i] = numGenerator(i, y[i - 1]);
  35.     for (int i = 0; i < N; i++)
  36.         cout << y[i] << ' ';
  37.     cout << endl;
  38.     bubbleSort(y, N);
  39.     for (int i = 0; i < N; i++) {
  40.         cout << y[i] << ' ';
  41.     }
  42.     cout << endl;
  43.     system("pause");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement