在調用三角函數之前先把角度換算成弧度,調用反三角函數之后把弧度換算成角度就可以了.可以用 pi = 4.0 * atan(1) 算出pi,用 a = h * 180.0/pi 算角度,用 h = a * pi /180 算弧度.
創新互聯公司于2013年開始,先為豐寧等服務建站,豐寧等地企業,進行企業商務咨詢服務。為豐寧企業網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。
從鍵盤輸入一個角度值,求出該角度的正弦值、余弦值和正切值。
#includeiostream
#includecmath
using namespace std;
const double pi(3.14159265);
void main()
{ double a,b;
cina;
b=a*pi/180;
cout"sin("a")="sin(b)endl;
cout"cos("a")="cos(b)endl;
cout"tan("a")="tan(b)endl;
}
求階乘
#includeiostream.h
int Factorial ( int ) ;
void main ()
{ int k ;
cout "Compute Factorial(k) , Please input k: " ;
cin k ;
cout k "! = " Factorial(k) endl ;
}
int Factorial ( int n )
{ if ( n == 0 )
return 1 ;
else
return n * Factorial ( n - 1 ) ;
}
x的n次方的函數
#include iostream
using namespace std;
double power (double x, int n);
void main(void)
{
cout "5 to the power 2 is " power(5,2) endl;
}
double power (double x, int n)
{
double val = 1.0;
while (n--)
val = val*x;
return(val);
}
math.h里的三角函數用的單位是弧度,你貌似錯在這里。 答案補充 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
#?include?stdio.h
#?include?math.h
#?define?pi?3.1415926
int?main(void)
{
double?a,n,result;
char?func_name[3];
printf("enter?the?name?of?triangle?function?:");
scanf("%s",func_name);
printf("enter?angel:");
scanf("%lf",a);
n=pi*a/180;
if?(strcmp(func_name,?"sin")?==?0)
result=sin(n);
if?(strcmp(func_name,?"cos")?==?0)
result=cos(n);
if?(strcmp(func_name,?"tan")?==?0)
result=tan(n);
printf("%0.2f\n",result);
return?0
;
}
調用math.h中的三角函數,需要將角度值變換為弧度值,代碼如下:
#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;
}
#include?stdio.h
#include?math.h
#define?PI?3.14159265
int?main()
{
double?ans?=?sqrt((1-cos(PI/3.0))/2.0);
printf?("%g\n",?ans);
return?0;
}
文章名稱:c語言求三角函數值 c語言三角形函數
網頁網址:http://m.kartarina.com/article6/hgeiog.html
成都網站建設公司_創新互聯,為您提供微信小程序、網站設計、云服務器、外貿建站、營銷型網站建設、面包屑導航
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯