#include <stdio.h> #include <conio.h> #include <math.h> void main() { int n = 3, i = 1; float S = 0, x = 3, T; float M = 0; while(i <= n) { M = M + i; T = pow(x, i); S = S + T / M; i++; } printf("S = %2.2f", S); getch(); }
Code chạy: while -> printf
1 <= 3 chạy M = M + i = 1 chạy T = pow(x, i) = x chạy S = S + T / M = x
2 <= 3 chạy M = M + i = 3 chạy T = pow(x, i) = x^2 chạy S = S + T / M = x + x^2/ 3
3 <= 3 chạy M = M + i = 6 chạy T = pow(x, i) = x^3 chạy S = S + T / M = x + x^2/ 3 + x^3 / 6
4 <= 3 dừng thoát in S = x + x^2/ 3 + x^3 / 6 = 10.5
