#include"stdio.h"
成都創(chuàng)新互聯(lián)是一家從事企業(yè)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、成都做網(wǎng)站、行業(yè)門戶網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計制作的專業(yè)網(wǎng)站設(shè)計公司,擁有經(jīng)驗豐富的網(wǎng)站建設(shè)工程師和網(wǎng)頁設(shè)計人員,具備各種規(guī)模與類型網(wǎng)站建設(shè)的實力,在網(wǎng)站建設(shè)領(lǐng)域樹立了自己獨特的設(shè)計風格。自公司成立以來曾獨立設(shè)計制作的站點1000+。
#include"math.h"
double mysin(double x)
{double y=x,t=x,t1=x*x;
for(int i=2;fabs(t)1e-10;i+=2)
{t*=-t1/(i*(i+1));
y+=t;
}
return y;
}
int main()
{ double x;
scanf("%lf",x);
printf("%f\n",mysin(x));
return 0;
}
C語言sin()用來計算參數(shù)x 的正玄值,然后將結(jié)果返回。返回-1 至1 之間的計算結(jié)果。
例子:
#include math.h
main(){
double answer = sin(0.5);
printf("sin(0.5) = %f\n", answer);
}
執(zhí)行
sin(0.5) = 0.479426
C語言sin():
sin()原型:double sin(double x)
sin()角度與弧度:
π=180°
1°=π/180
1(rad)=180/π
角度轉(zhuǎn)弧度:用角度乘以π/180
弧度轉(zhuǎn)角度:用弧度乘以180/π,或者用rtod()函數(shù)
擴展資料:
與sin相似的acos函數(shù)
函數(shù)名: acos
功 能:計算并返回arccos(x)值、要求-1=X=1
函數(shù)與形參類型:
double acos(x)
double x;
程序例:
#include stdio.h
#include math.h int main(void)
{
double result;
double x = 0.5; result = acos(x);
printf("The arc cosine of %lf is %lf\n", x, result);
return 0;
}
參考資料:CSDN博客頻道-C語言中sin和cos的用法
#includestdio.h
#includemath.h
double?sin(double);
double?nResult(double,double);
int?main()
{
double?x=0;
scanf("%lf",x);
printf("sin(%lf)=%lf\n",x,sin(x));
return?0;
}
double?sin(double?x)
{
//sin(x)=x-x^3/3!+x^5/5!-x^7/7!+……+(-1)(n^2n+1)/(2n+1)!+……
int?i=0;
double?result=0,n=0;
while(?fabs(?n=nResult(x,2*++i-1)?)??0e-5?)//絕對值大于10^-5次方就循環(huán)
result+=(i%2==1)?n:-n;
return?result;
}
double?nResult(double?x,double?n)
{
//(n^2n+1)/(2n+1)!也就是n/1*n/2*n/3*n/4*.....n/(2n+1)
return?n==1?x:nResult(x,n-1)*x/n;
}