當前位置:首頁 » 編程語言 » c語言求三角函數

c語言求三角函數

發布時間: 2023-02-01 01:21:27

① 如何用c語言實現三角函數的計算

包含頭文件math.h後,所有三角函數的庫函數就都可以直接引用了。比如求x的正弦就用sin(x),它返回一個double值。注意x以弧度計……

② C語言怎樣表示三角函數計算(註:要用「角度制」表示)編出代碼

調用math.h中的三角函數,需要將角度值變換為弧度值,代碼如下:
#include<stdio.h>
#include<math.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;
}

③ c語言編寫三角函數

求sin的:參考下 #include<stdio.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/b<0.0000001) break; else { if(count%2==0) sum-=a/b; else sum+=a/b; } } printf("%lf\n",sum); }

④ C語言怎樣表示三角函數計算(註:要用「角度制」表示)

在調用三角函數之前先把角度換算成弧度,調用反三角函數之後把弧度換算成角度就可以了.可以用 pi = 4.0 * atan(1) 算出pi,用 a = h * 180.0/pi 算角度,用 h = a * pi /180 算弧度.

⑤ C語言求三角函數

sum = fun(x,y,z); //這里,應當接收函數的返回值
printf("f(x,y,z)=%f\n",sum);

⑥ C語言怎樣表示三角函數計算(註:要用「角度制」表示)..

C語言中的三角函數計算需要將角度轉弧度,,比如以下代碼是計算sin()的值:
#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);
}

⑦ 求三角函數的C語言演算法

從鍵盤輸入一個角度值,求出該角度的正弦值、餘弦值和正切值。
#include<iostream>
#include<cmath>
using namespace std;
const double pi(3.14159265);
void main()
{ double a,b;
cin>>a;
b=a*pi/180;
cout<<"sin("<<a<<")="<<sin(b)<<endl;
cout<<"cos("<<a<<")="<<cos(b)<<endl;
cout<<"tan("<<a<<")="<<tan(b)<<endl;
}
求階乘
#include<iostream.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);
}

⑧ 如何用C語言進行三角函數的計算,比如知道sinx=0.5,求cos和tanx。怎麼寫

在C的math.h是有專門的三角函數和反三角函數的。
所以
你這個
x=asin(0.5)
輸出
cos(x)

tan(x)就可以了。

⑨ 求一個計算三角函數的C語言程序(不要使用C庫,要自己定義函數)

#include
#include
int main()
{
double n; //sin cos是函數,不能定義成變數
scanf("%lf",&n);
n=sin(n); //求n的sin()值,並返回給n
printf("%lf\n",n);//輸出n
return 0;
}

⑩ C語言三角函數求值,

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

熱點內容
蘋果存儲空在哪裡 發布:2024-05-08 10:37:16 瀏覽:641
python獲取系統時間 發布:2024-05-08 10:32:24 瀏覽:634
瀏覽器上傳文件 發布:2024-05-08 10:31:17 瀏覽:91
編程強度高 發布:2024-05-08 10:24:59 瀏覽:279
電腦如何查看型號和配置 發布:2024-05-08 10:19:56 瀏覽:421
大地電子保單pdf密碼多少 發布:2024-05-08 09:54:21 瀏覽:861
ftp掃描免費主機 發布:2024-05-08 09:50:05 瀏覽:340
聽說ftpmp4 發布:2024-05-08 09:39:51 瀏覽:476
退貨上傳圖片 發布:2024-05-08 09:38:38 瀏覽:80
linux命令安裝rpm 發布:2024-05-08 09:37:37 瀏覽:644