Đề bài: Implement functions with the following prototypes:
double sinx(double x, double epsi) – In: x, epsi; Out: sin(x) with precision < epsi
Mọi người xem giúp mình xem mình code sai chỗ nào, chỉ mình chút! Cảm ơn!
Công thức tính sinx: sin(x)=x-(x^3/3!)+(x^5/5!)+....+{(-1)^n*x^(2n+1)}/(2n+1)!
Mã:
#include <stdio.h>
#include <conio.h>
#include <math.h>
double sinx(double x,double epsi)
{
double sin,m=1,t,ps;
int i=1;
sin=x;
while(t/m>=epsi)
{
t = pow(-1,i)*pow(x,(2*i+1));
m = m*(2*i)*(2*i+1);
i++;
sin=sin+t/m;
}
return sin;
}
int main()
{
double x,epsi;
printf("x= ");
scanf("%lf",&x);
printf("Sai so epsi: ");
scanf("%lf",&epsi);
printf("sin(%lf)= %lf",x,sinx(x,epsi));
getch();
return 0;
}
View more random threads:
Ngoại trừ một số ít trường hợp rãnh mũi - má và “râu rồng silicon” xuất hiện sớm, có khi từ tuổi thanh niên do cơ địa, còn lại, đại đa số do căn do lão hoá đã gây nên ba diễn biến: Giảm mô xương gò...
Cách thẩm mỹ má ở tuổi trung niên...