C語言中的三角函數(shù)計(jì)算需要將角度轉(zhuǎn)弧度,,比如以下代碼是計(jì)算sin()的值:
成都創(chuàng)新互聯(lián)是一家專注于網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),信州網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:信州等地區(qū)。信州做網(wǎng)站價格咨詢:18982081108
#include"stdio.h"
#include"math.h"
#define PI 3.1415926
main()
{
int i;
float t;
printf("請輸入要計(jì)算的角度:");
scanf("%d",i);
t=sin(180*i/PI);
printf("sin(%d)=%f",i,t);
}
sum = fun(x,y,z); //這里,應(yīng)當(dāng)接收函數(shù)的返回值
printf("f(x,y,z)=%f\n",sum);
math.h里的三角函數(shù)用的單位是弧度,你貌似錯在這里。 答案補(bǔ)充 Example
/* SINCOS.C: This program displays the sine, hyperbolic
* sine, cosine, and hyperbolic cosine of pi / 2.
*/
#include math.h
#include stdio.h
void main( void )
{
double pi = 3.1415926535;
double x, y;
x = pi / 2;
y = sin( x );
printf( "sin( %f ) = %f\n", x, y );
y = sinh( x );
printf( "sinh( %f ) = %f\n",x, y );
y = cos( x );
printf( "cos( %f ) = %f\n", x, y );
y = cosh( x );
printf( "cosh( %f ) = %f\n",x, y );
} 答案補(bǔ)充 Output
sin( 1.570796 ) = 1.000000
sinh( 1.570796 ) = 2.301299
cos( 1.570796 ) = 0.000000
cosh( 1.570796 ) = 2.509178
Parameter
x
Angle in radians
調(diào)用math.h中的三角函數(shù),需要將角度值變換為弧度值,代碼如下:
#includestdio.h
#includemath.h
#define PI 3.14159265359
int main()
{
float st,a;
scanf("%f",st);
a = st * PI/180;
printf("sin(st)=%f\n", sin(a));
printf("cos(st)=%f\n", cos(a));
return 0;
}