Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- double sum(double alpha) {
- double total_sum = 0; // сумма с новым слагаемым
- int denominator; // знаменатель a_i
- double numerator = 1; // числитель a_i
- double a_i; // a_i
- for (int i = 1; true; i++) {
- denominator = (1 + i*i*i)*(1 + i*i*i);
- numerator *= (-1);
- a_i = i * numerator / denominator;
- cout << "a_i " << a_i << endl;
- total_sum += a_i;
- if (abs(a_i) <= alpha) { // первое отброшенное слагаемое
- return total_sum;
- }
- }
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- double alpha = 0.00000001; // Требуемая точность
- double exact_value = -0.2284153977; // Значение суммы ряда до 10 знака после запятой
- double Sum = sum(alpha);
- cout << "Значение суммы ряда: " << exact_value << endl;
- cout << "Приближенное значение суммы ряда: t" << Sum << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment