#include <stdio.h> #include <conio.h> #include <math.h> int main() { long n = 2; float x = 3; float S = 0, T, M = 1; int i = 2, j = 1; while(i <= 2 * n) { T = pow(x, i); M = M * i * j; S = S + T / M; i = i + 2; j = j + 2; } printf("S = %2.3f", S + 1); getch(); }
Code chạy: while -> printf
2 <= 2 * 2 = 4:
T = x^2, M = 1.1.2, S = x^2 / (1.2)
4 <= 2 * 2 = 4:
T = x^4, M = 1.1.2.4.3, S = x^2 / (1.2) + x^4 / (1.2.3.4)
5 <= 4 dừng thoát in S = x^2 / (1.2) + x^4 / (1.2.3.4) + 1 = 8.875
