T
T
Talge2020-10-08 19:00:49
C++ / C#
Talge, 2020-10-08 19:00:49

How to calculate the value of the integral (sint/t)dt as the sum of M series terms?

I am a university student and this is our laboratory work

Task:
Calculate the value of the integral (sint/t)dt (from 0 to x) as the sum of M terms of the series: x - ((x^3)/(3*3!)) + (( x^5)/(5*5!)) - ... + ((x^n)/(n * n!))

I didn't quite understand the problem statement, but I tried to write the code. Does my code solve the problem? If not, what needs to be fixed?

#include <iostream>
#include <cmath>

int main() {
        int m = 0;
        double x = 0;
        std::cin >> x;
        double a = x;
        double result = 0;
        std::cin >> m;
        if (m < 0) {
                std::cout << "M < 0" << std::endl;
                return 0;
        } else if (m == 0) {
                std::cout << 0 << std::endl;
                return 0;
        }
        result = a;
        int n = 1;
        for (int i = 1; i < m; i++) {
                n += 2;
                a *= -pow(x / n, 2) * (n - 2) / (n - 1);
                result += a;
        }
        std::cout << result << std::endl;

        return 0;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question