Advertisement
Balda

Untitled

Jan 9th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. double sum(int n, double a);
  7. double sum_sin();
  8. void formula(int n);
  9.  
  10. double sum_sin()
  11. {
  12.     double sum = 0;
  13.     for (double i = 0.1; i <= 10; i = i + 0.1)
  14.     {
  15.         sum = sum + (1 + sin(i));
  16.     }
  17.     return sum;
  18. }
  19.  
  20. double sum(int n, double a)
  21. {
  22.     double sum = 0;
  23.     int fact = 1;
  24.     for (int i = 1; i <= n; i++)
  25.     {
  26.         fact = fact*i;
  27.         sum = sum + a / fact;
  28.     }
  29.     return sum;
  30. }
  31.  
  32. void formula(int n)
  33. {
  34.     cout << endl;
  35.     float *v = new float[n];
  36.     v[0] = 0; v[1] = 0; v[2] = 1.5;
  37.     for (int i = 3; i<n; i++){
  38.         if (n >= 4)
  39.         {
  40.             cout << v[0] << ' ' << v[1] << ' ' << v[2] << endl;
  41.             v[i] = ((i + 1) / (i*i + 1)*v[i - 1] - v[i - 2] * v[i - 3]);
  42.             cout << i << endl;
  43.         }
  44.         if (n - 1 == i)  cout << "V" << n << "=" << v[i];
  45.     }  cout << endl;
  46.     for (int j = 0; j<n; j++)
  47.         cout << v[j] << ' ';
  48. }
  49.  
  50. int main()
  51. {
  52.     setlocale(LC_ALL, "Russian");
  53.     int n;
  54.     double a;
  55.     cout << "1 задание. Посчитать a/1! ... a/n!" << endl;
  56.     cout << "n: ";
  57.     cin >> n;
  58.     cout << "a: ";
  59.     cin >> a;
  60.     cout << "Результат: " << sum(n, a) << endl;
  61.  
  62.     cout << "2 задание. Посчитать 1+sin(0.1) ... 1+sin(10)" << endl;
  63.     cout << "Результат 2: " << sum_sin() << endl;
  64.    
  65.     cout << "3 задание. Посчитать по формуле" << endl;
  66.     cout << "Введите n:";
  67.     cin >> n;
  68.     if (n >= 4) formula(n);
  69.     else cout << "\aВнимание N < 4!";
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement