// tinh tong s = s + (x ^ n)/(2*n+1)!
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float x;
int i, n;
float s;
long t, m, p;
t = 0;
p = 1;
s = 0;
i = 1;
do
{
printf("\nnhap x: ");
scanf("%f", &x);
printf("\nnhap n: ");
scanf("%d", &n);
if(n < 1)
{
printf("\nnhap lai n!");
}
}while(n < 1);
while(i <= n)
{
t = pow(x, n);
m = 2 * i + 1;
p = m * (m - 1);
s =s + float (t/p);
i++;
}
printf("\ntong la %5.2f", s);
getch();
return 0;
}
Đã được chỉnh sửa lần cuối bởi Hieu Luyn : 26-09-2017 lúc 12:24 PM.
Cả t lẫn p đều có kiểu long nên biểu thức t/p cũng thế, nên t/p == 0, nên float(t/p) == 0.0, nên s == 0.0.
-...- -.- .. .-.. .-.. - .... . -... . .- ... - .-.-.