Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include "stdafx.h"
- //#include <conio.h>
- #include <cmath>
- #include <clocale>
- #include <iostream>
- #include <functional>
- double count_n(const std::pair<std::int32_t,std::int32_t>& preconditions,std::size_t n, const std::function<double(double b, double c)>& relax){
- double result, a = preconditions.first, b = preconditions.second;
- if (n < 3){ return (n == 1? a:b); }
- for(int i = 3; i <= n; i++){
- result = relax(a, b);
- a = b; b = result;
- }
- return result;
- }
- double relax_23(double b, double c){ return sin(c) + 10*b; }
- double relax_24(double b, double c){ return sqrt(c) + sqrt(b); }
- double relax_25(double b, double c){ return sqrt(c+10) + (b+2)*(b+2); }
- double relax_26(double b, double c){ return (c+b)/10; }
- double relax_27(double b, double c){ return (c+10)*b; }
- double relax_28(double b, double c){ return (c*b)/10; }
- int main(int argc, char* argv[]){
- std::size_t task_number, number_index;
- std::function<double(double b, double c)> relax_function;
- std::pair<std::int32_t,std::int32_t> preconditions;
- //std::setlocale(LC_ALL,"Russian")
- while(true){
- std::cout << "Введите номер последовательности:>";
- std::cin >> task_number;
- std::cout << "Введите номер числа в последовательности:>";
- std::cin >> number_index;
- switch (task_number) {
- case 23:
- relax_function = relax_23;
- preconditions = {0,1};
- break;
- case 24:
- relax_function = relax_24;
- preconditions = {0,1};
- break;
- case 25:
- relax_function = relax_25;
- preconditions = {0,1};
- break;
- case 26:
- relax_function = relax_26;
- preconditions = {0,1};
- break;
- case 27:
- relax_function = relax_27;
- preconditions = {10,1};
- break;
- case 28:
- relax_function = relax_28;
- preconditions = {1,2};
- break;
- default:
- std::cout << "Неверный номер последовательности.\n";
- return 0;
- }
- printf("В последовательности %lu число под номером %lu = %f\n",task_number,number_index, count_n(preconditions,number_index,relax_function));
- }
- //getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement