Đề 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:
xã hội vững mạnh, nhu cầu mặc đẹp của con người ngày càng cao. ngành công nghiệp thời trang cũng đang vững mạnh chóng vánh. những nhà máy gia công hàng may mặc chẳng thể đóng góp lặng thầm vào sự...
Tìm xưởng may gia công tại TP Hồ...