Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- double sum(int n, double a);
- double sum_sin();
- void formula(int n);
- double sum_sin()
- {
- double sum = 0;
- for (double i = 0.1; i <= 10; i = i + 0.1)
- {
- sum = sum + (1 + sin(i));
- }
- return sum;
- }
- double sum(int n, double a)
- {
- double sum = 0;
- int fact = 1;
- for (int i = 1; i <= n; i++)
- {
- fact = fact*i;
- sum = sum + a / fact;
- }
- return sum;
- }
- void formula(int n)
- {
- cout << endl;
- float *v = new float[n];
- v[0] = 0; v[1] = 0; v[2] = 1.5;
- for (int i = 3; i<n; i++){
- if (n >= 4)
- {
- cout << v[0] << ' ' << v[1] << ' ' << v[2] << endl;
- v[i] = ((i + 1) / (i*i + 1)*v[i - 1] - v[i - 2] * v[i - 3]);
- cout << i << endl;
- }
- if (n - 1 == i) cout << "V" << n << "=" << v[i];
- } cout << endl;
- for (int j = 0; j<n; j++)
- cout << v[j] << ' ';
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n;
- double a;
- cout << "1 задание. Посчитать a/1! ... a/n!" << endl;
- cout << "n: ";
- cin >> n;
- cout << "a: ";
- cin >> a;
- cout << "Результат: " << sum(n, a) << endl;
- cout << "2 задание. Посчитать 1+sin(0.1) ... 1+sin(10)" << endl;
- cout << "Результат 2: " << sum_sin() << endl;
- cout << "3 задание. Посчитать по формуле" << endl;
- cout << "Введите n:";
- cin >> n;
- if (n >= 4) formula(n);
- else cout << "\aВнимание N < 4!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement