Advertisement
Balda

Untitled

Jan 9th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. double Fact(int);
  6. double Count1(int n);
  7. double Count2(int n, float a);
  8. double Count3(float a);
  9.  
  10. double Count1(int n)
  11. {
  12.     double S = 0;
  13.     for (int i = 1; i <= n; i++)  S += 1 / Fact(i);
  14.     return S;
  15. }
  16.  
  17. double Count2(int n, float a)
  18. {
  19.     float P = 1;
  20.     for (int i = 0; i <= n; i++)  P *= (a - i*n);
  21.     return P;
  22. }
  23.  
  24. double Count3(float a)
  25. {
  26.     int n;
  27.     float x, x0;
  28.     if (a <= 1)
  29.     if (2 * a <= 0.95) x0 = 2 * a;
  30.     else x0 = 0.95;
  31.     else
  32.     if (a<25) x0 = a / 5;
  33.     else x0 = a / 25;
  34.     n = 0; x = x0;
  35.     cout << endl << "x0=" << x0;
  36.     do
  37.     {
  38.         x0 = x;
  39.         n = n + 1;
  40.         x = 4 / 5 * x0 + a / (5 * pow(x0, 4));
  41.     } while (5 / 4 * a*abs(x - x0) >= 0.000001);
  42.     return x;
  43. }
  44. int main()
  45. {
  46.     setlocale(LC_ALL, "Russian");
  47.     int n;
  48.     cout << "Задача 1" << endl;
  49.     cout << "Введите n:";
  50.     cin >> n;
  51.     cout << endl << "S=" << Count1(n);
  52.  
  53.     float a;
  54.     cout << endl << endl << "Задача 2" << endl;
  55.     cout << "Введите a: "; cin >> a; cout << "Введите n: "; cin >> n;
  56.     cout << endl << "P=" << Count2(n, a);
  57.  
  58.  
  59.     cout << endl << endl << "Задача 3" << endl;
  60.     cout << "Введите a: "; cin >> a;
  61.     cout << endl << "x(" << n << ") = " << Count3(a) << endl;
  62. }
  63.  
  64.  
  65. double Fact(int n)
  66. {
  67.     int i;
  68.     double F = 1;
  69.     for (i = 1; i <= n; i++)  F *= i;
  70.     return F;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement