# Untitled

unknown
plain_text
7 months ago
1.3 kB
3
Indexable
Never
```#include <iostream>
#include <cmath>

double s1(int n, double x) {
double result = 0;
for (int i = 1; i <= n; ++i) {
result += (pow(x, i)) / (i * (i + 1));
}
return result;
}

int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}

double s2(int n) {
double result = 0;
for (int i = 0; i <= n; ++i) {
result += 1.0 / factorial(i);
}
return result;
}

double s3(int n, double x) {
double result = 0;
for (int i = 0; i <= n; ++i) {
result += pow(x, 2 * i + 1);
}
return result;
}

double s4(int n, double x) {
return s1(n, x) * 1 + s2(n) * 2 + s3(n, x) * 3;
}

int main() {
int n;
double x;
std::cout << "Nhap gia tri cua n: ";
std::cin >> n;
std::cout << "Nhap gia tri cua x: ";
std::cin >> x;

double result1 = s1(n, x);
std::cout << "Ket qua: " << result1 << std::endl;
double result2 = s2(n);
std::cout << "Ket qua: " << result2 << std::endl;
double result3 = s3(n, x);
std::cout << "Ket qua: " << result3 << std::endl;
double result4 = s4(n, x);
std::cout << "Ket qua: " << result4 << std::endl;

return 0;
}```