Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- double Fact(int);
- double Count1(int n);
- double Count2(int n, float a);
- double Count3(float a);
- double Count1(int n)
- {
- double S = 0;
- for (int i = 1; i <= n; i++) S += 1 / Fact(i);
- return S;
- }
- double Count2(int n, float a)
- {
- float P = 1;
- for (int i = 0; i <= n; i++) P *= (a - i*n);
- return P;
- }
- double Count3(float a)
- {
- int n;
- float x, x0;
- if (a <= 1)
- if (2 * a <= 0.95) x0 = 2 * a;
- else x0 = 0.95;
- else
- if (a<25) x0 = a / 5;
- else x0 = a / 25;
- n = 0; x = x0;
- cout << endl << "x0=" << x0;
- do
- {
- x0 = x;
- n = n + 1;
- x = 4 / 5 * x0 + a / (5 * pow(x0, 4));
- } while (5 / 4 * a*abs(x - x0) >= 0.000001);
- return x;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n;
- cout << "Задача 1" << endl;
- cout << "Введите n:";
- cin >> n;
- cout << endl << "S=" << Count1(n);
- float a;
- cout << endl << endl << "Задача 2" << endl;
- cout << "Введите a: "; cin >> a; cout << "Введите n: "; cin >> n;
- cout << endl << "P=" << Count2(n, a);
- cout << endl << endl << "Задача 3" << endl;
- cout << "Введите a: "; cin >> a;
- cout << endl << "x(" << n << ") = " << Count3(a) << endl;
- }
- double Fact(int n)
- {
- int i;
- double F = 1;
- for (i = 1; i <= n; i++) F *= i;
- return F;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement