Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define _USE_MATH_DEFINES
- #include <math.h>
- using namespace std;
- int h = -1;
- float calc(int y);
- double rec(long);
- int main()
- {
- setlocale(LC_ALL, "Russian");
- long n;
- char ex = 'n';
- do {
- cout << "Введите номер задания: " << endl;
- char task;
- cin >> task;
- switch (task)
- {
- case '1': {
- float x;
- int n;
- cout << "Enter n: " << endl;
- cin >> n;
- x = calc(2 * n + 1);
- cout << "Your result: " << x << endl;
- break;
- }
- case '2': {
- long n;
- cout << "Enter n: " << endl;
- cin >> n;
- double x;
- x = rec(n);
- cout << "Your result: " << 1.0 / 3 + (n * n) / x << endl;
- break;
- }
- default: {cout << "Нет такой задачи.\n"; } break;
- }
- cout << "Если вы хотите выйти, нажмите \'y\', в противном случае-любую другую клавишу" << endl;
- cin.ignore(100, '\n');
- cin >> ex;
- } while (ex != 'y');
- return 0;
- }
- float calc(int y)
- {
- h += 2;
- float rez = 0;
- if (h < y)
- rez = h + (1.0 / calc(y));
- else
- rez = h;
- return rez;
- }
- double rec(long i)
- {
- static long n = i;
- if (i == 1)
- {
- return (1.0 / 3);
- }
- else
- {
- return (1.0 / (pow(3, i))) * rec(i - 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement