C語言中的三角函數(shù)計算需要將角度轉(zhuǎn)弧度,,比如以下代碼是計算sin()的值:
創(chuàng)新互聯(lián)建站于2013年開始,先為崇仁等服務(wù)建站,崇仁等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為崇仁企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
#include"stdio.h"
#include"math.h"
#define PI 3.1415926
main()
{
int i;
float t;
printf("請輸入要計算的角度:");
scanf("%d",i);
t=sin(180*i/PI);
printf("sin(%d)=%f",i,t);
}
math.h里的三角函數(shù)用的單位是弧度,你貌似錯在這里。 ? 答案補充 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 );
} ?答案補充 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;
}
求sin的:參考下 #includestdio.h void main() { double x,a,b,sum=0; printf("請輸入x的弧度值:\n"); scanf("%lf",x); int i,j,count=0; for(i=1;;i+=2) { count++; a=b=1; for(j=1;j=i;j++) { a*=x; b*=(double)j; } if(a/b0.0000001) break; else { if(count%2==0) sum-=a/b; else sum+=a/b; } } printf("%lf\n",sum); }
文章標題:c語言三角函數(shù)程序怎么寫 c語言三角函數(shù)的程序例
本文鏈接:http://www.muchs.cn/article48/dohiihp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、Google、動態(tài)網(wǎng)站、網(wǎng)站排名、做網(wǎng)站、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)