SLIDE1

Sunday, December 28, 2014

viết hàm tính sin(x) - bài tập lập trình c


//viết hàm tính sin(x)
#include<stdio.h>
#include<conio.h>
#include<math.h>
double sin(double x)
{
double ps = x, i = 1, tong = x,dau=-1;
while (fabs(ps) > 0.00001)
{
ps = ps*x*x / ((i + 1)*(i + 2));
tong += dau*ps;
dau = -dau;
}
return tong;
}
void main()
{
double x;
printf("x="); scanf_s("%lf", &x);
printf("%lf\n", sin(x));
}